jargon

Comparison

InheritancevsYo-yo problem

Inheritance

you got twenty methods you never asked for along with the one you wanted, and you cannot give any of them back.

Deriving a class from another so it acquires the parent's fields and methods and may replace some of them. It is the strongest coupling one class can have to another: the subclass depends not just on the parent's public surface but on which of its own methods the parent calls internally. That is why it is the default in textbooks and increasingly the second choice in practice.

Full entry →

Yo-yo problem

understanding one method meant opening five files up and down the hierarchy, and then going back up again.

The reading cost of a deep inheritance hierarchy, where following the actual behaviour of a call means moving repeatedly between ancestors and descendants. It is the concrete, measurable objection to deep hierarchies — not that they are inelegant, but that nobody can hold one in their head. Flattening and composing is what removes it, at the cost of some explicit delegation.

Full entry →

Related comparisons