dvas0004 / NerdNotes

A collection of notes: things I'd like to remember while reading technical articles, technical questions I couldn't answer, and so on.
12 stars 0 forks source link

OOP: Composition over inheritance #27

Open dvas0004 opened 5 years ago

dvas0004 commented 5 years ago

(a.k.a. composite reuse principle). Prefer composition (i.e. a class containing an instance of another class) over inheritance (i.e. "extends" or similar)

Think in terms of what an object can do as opposed to what an object is: "HAS A" vs "IS A"

Benefits are more flexibility, easier thought processing and longer-term stability of objects

dvas0004 commented 5 years ago

https://en.wikipedia.org/wiki/Composition_over_inheritance