Alternative to "inheritance v composition??"
Posted
by
Frank
on Programmers
See other posts from Programmers
or by Frank
Published on 2012-11-12T16:59:31Z
Indexed on
2012/11/12
17:19 UTC
Read the original article
Hit count: 291
I have colleagues at work who claim that "Inheritance is an anti-pattern" and want to use composition systematically instead, except in (rare, according to them) cases where inheritance is really the best way to go. I want to suggest an alternative where we continue using inheritance, but it is strictly forbidden (enforced by code reviews) to use anything but public members of base classes in derived classes. For a case where we don't need to swap components of a class at runtime (static inheritance), would that be equivalent enough to composition? Or am I forgetting some other important aspect of composition?
© Programmers or respective owner