Re: Design question: polymorphism after object creation
On Mar 30, 10:23 am, "Alf P. Steinbach" <al...@start.no> wrote:
* James Kanze:
On Mar 29, 1:34 am, Marcel M=FCller <news.5.ma...@spamgourmet.com>
Even an object, that is not fully complete, has some basic
properties. It may be selected, it may be referenced, it has
a changeable display name and so on. NULL is not sufficient.
In other words, your base class has some behavior. Logically,
this means either the template method pattern or the strategy
pattern---the latter means that you can defer the decision, and
change the implementation at will.
As I wrote else-thread, IMHO it's not a good idea to add
complexity just for ideological reasons.
Where are the ideological reasons here? He's described a
problem which he wants solved. I don't know enough about his
application to say whether it's appropriate for his base class
to have behavior, but there are certainly cases where it is.
The template method pattern and the strategy pattern are widely
used to solve real problems. Not just for ideological reasons.
Objects that modify themselves to provide richer
functionality, where that metamorphosis is (1) costly and (2)
can fail, well it's just silly.
Objects that modify themselves in accordance to the design
specification are perfectly reasonable. Without knowing his
application, it's impossible to know whether this particular
design is appropriate, but if it is, the strategy pattern is a
standard, well established and effective solution.
Instead keep the distinction between URI or directory entry or
whatever, on the one hand, and what's referred to, on the
other hand. They might implement some common interface. But I
can't for the life of me see the point in having e.g. a
directory entry metamorphose into a file it represents.
Again, I don't know exactly what he's doing, so I can't say.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34