[Tutor] Transforming object into subclass instance
lists at janeden.org
Sun Oct 30 17:00:37 CET 2005
my program uses an initial "switch" statement to create an object:
valid_types = dict(
# ... code ommitted...
page = valid_types[type]]()
For a certain class, it is only during the execution of the __ini__ method that I can distinguish between two subtypes (subclasses). The subclasses define two different versions of method A.
Now my question is: How can I turn an object of class X into an object of either class Y or Z while (retaining all the attributes defined so far).
I know I could solve the problem by using another switch statement - but is there consistent OOP solution for this problem?
Hanlon's Razor: Never attribute to malice that which can be adequately explained by stupidity.
More information about the Tutor