Settings

Theme

OOP: A practical alternative to Inheritance

github.com

12 points by clownvorld 3 years ago · 3 comments

Reader

karmakaze 3 years ago

The diamond example "TA extends Student, Teacher" seems worse than OO or direct composition. It's either a compiler error or share everything that overlaps.

I would have made the sharing explicit during composition--a Teacher or Student is given the Person instance when constructed, so sharing or not sharing is decided at composition time. To enforce consistency use helper/static methods.

  • zeedude 3 years ago

    Not sure what you’re getting at, sharing here does for you exactly what you would do with explicit composition.

jokethrowaway 3 years ago

Favor composability over inheritance.

That said plenty of languages don't have inheritance and work just fine.

Traits / Interfaces are a personal sweet spot

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection