I have the following situation :
class GenericObject{
virtual Attribute* getAttribute(){..}
}
class PlaneObject : public GenericObject{
Attribute1* getAttribute()override{..}
}
-----------------------------------------block1
class Attribute{
virtual GenericObject* getObject(){..}
}
class Attribute1 : public Attribute{
PlaneObject* getObject()override{..}
}
----------------------------------------block2
Since i'm overriding the getAttribute() methods in PlaneObject, changing its return type from Attribute* to Attribute1* , this is only allowed if the compiler is aware that Attribute1 is derived from Attribute.
Then I should put block2 before block1.
However, block2 also needs to know that PlaneObject is derived from GenericObject, in order to compile, because of the overridden methods in Attribute1 class.
I don't know if it is just bad design pattern or what. I've been looking for similar questions but didn't find the exact same picture i'm facing.