Yosi,
Just as Ernest suggested, you might want to have some logic to avoid such scenarios. In that case, you might want to encapsulate the class creation logic in a class factory and not instantiate the objects directly. This might be overkill for simple projects but certainly worth the pain if you have to apply complex logic to determine the class/subclass that you need to create under certain preconditions and dont want to repeat the logic everywhere. There is more to the factory
pattern, but you might use it to yor advantage in situations like this too.
Kindof like:
instead of doing :
MyObject o = new MyObject(params...);
do:
MyObject o = MyObjectFactory.CreateMyObject(params...);
CreateMyObject will contain the logic of determinining a valid MyObject to return.
-ortimus
"Simplicity is virtue"