I asked this question a few days ago and got VERY good answers from various monks (Masem knobunc tye tilly bikeNomad). Many thanks!
I'm pondering on the problem since. Not the programmatical solutions but the concepts behind.
Let me draw two pictures, that will show the two concepts:
1. Using a connection object to talk to the server:
Using this model, I can exchange the server object at will, because everything is talking to the connection.+----------+ +--------------+ +-------+ | | | | | | | server | <----> | connection | <----> | gui | | | | | | | +----------+ +--------------+ +-------+ \ \ +-------------+ | | | something | | else | | | +-------------+
2. Using a server object, that will change it's class:
Using this model, I cannot exchange the server object at will, because everything is talking to it directly and I had to inform every other object about the change. Hence the reblessing and I don't have to change anything.+----------+ +-------+ | | | | | server | <----> | gui | | | | | +----------+ +-------+ \ \ +-------------+ | | | something | | else | | | +-------------+
From the object oriented view, model one is cleaner and in other languages the only possibility.
From the real world view, model two is closer to what one thinks and only possible in perl (I think, but I don't know every language in the world).
Since I tend to think that OO should represent the real world and how we think about it, I find model two more plausible. I wouldn't ask a connection about the state of a server, I would ask the server!
What do you think?
In reply to Reblessing by busunsl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |