Imagine I have the following code:
class A: pass class B(A): pass class C(A): def __init__(self): self.b = B()
Is the above code correct in terms of correct inheritance? I mean is it a good practice to reference another subclass in a subclass?
Bags and suitcases are both types of containers. You can also put bags inside suitcases, and vice versa. Containment doesn't care about inheritance, and inheritance doesn't care about containment.
The two concepts are entirely orthogonal, and as such there is no 'best practice' here.
It depends. In some languages (like Java), you don't really have a choice because every class (except
Object) is a subclass.
C needs some functionality from class
B to do its work, but you can't describe instances of class
C as also being instances of class
C can't work as a drop-in replacement for
B), then your design is absolutely correct.