Re: Design question: polymorphism after object creation
Alf P. Steinbach wrote:
it is not that easy, since file/directory was only an example. In fact
almost any URI can turn into a container once the server is connected
and some protocol talk has happened.
It's IMHO silly to turn URI's into what they refer to.
URI is a property of what they refer to. Not more, not less.
No more bugs than any other derived class. In fact I only want to
intercept the construction process at the point where the base object
is fully constructed and before the derived class starts to build. I
see no point where this breaks with some OOP rule, at least as long as
the base is not abstract. Unfortunately the language does not provide
a feature to do this,
It's trivially easy: last statement of base class constructor body.
If and only if I can block the thread that executes the constructor.
Unfortunately having one thread per object is absolutely not an option.
because a cannot call the constructor of a derived class without
invoking the constructor of the base anew.
This may be some other problem, or more in the direction of the real
problem. I have the feeling your descriptions are less than complete,
because it doesn't fit in with what you have described so far.
Well, reducing the application code to a minimal example is always
complicated. Maybe I did not hit the nail on the head.
see the FAQ about how to do derived class specific initialization.
I don't know which part you refer to.
What's difficult about copying state, or referring to it.
I cannot copy the state of a mutex. I have to refer to it. Similar
things applies to the observable property (But this one can be swapped).
But referring from the specialized class to it's 'base' is not that
straight forward. Also the base has to forward all calls to 'virtual
functions' to it's specialized counter part.