Java Composition Over Inheritance

Choosing between inheritance, composition and sealed hierarchies in Java: fragile base classes, self-use of overridable methods, subclass explosion, the costs of delegation and decoration, sealed types with exhaustive switch as the modern middle ground, and the cases where inheritance is genuinely right. Use when reviewing an `extends` between classes you maintain, when a base-class change broke subclasses, when variants multiply along more than one axis, or when designing a new hierarchy. Does not cover behavioural substitutability formalism (java-design-by-contract) or the SOLID framing of LSP (java-solid).

robsonkades a0d715c 4 files · 20.8 KB Updated

File contents

robsonkades/agent-skills/tree/main/skills/java-composition-over-inheritance commit a0d715c8e0

Frequently asked questions

npx skillmds@latest add robsonkades/java-composition-over-inheritance