Replace Inheritance with Delegation

Domain: Refactoring

🎯 Motivation

Inheritance is for β€œis-a” relationships, but often misused for code reuse. When a subclass only wants some parent behavior, delegation (holding a reference) is more flexible and safer.

πŸ“‹ Concrete Example

A Stack should not inherit Vector just to reuse storage. Instead, Stack holds a list internally and delegates push and pop to it, exposing only stack-like methods.

πŸ”— Analogy

You do not become a professional chef to use their kitchen. You rent the kitchen and hire the chef for specific tasks β€” you get what you need without the unwanted obligations.