🔥 Burn Fat Fast. Discover How! 💪

4. When is classical inheritance an appropriate choice? The a | Coding interview preparation

4. When is classical inheritance an appropriate choice?

The answer is never, or almost never. Certainly never more than one level. Multi-level class hierarchies are an anti-pattern. I’ve been issuing this challenge for years, and the only answers I’ve ever heard fall into one of several common misconceptions. More frequently, the challenge is met with silence.

“If a feature is sometimes useful
and sometimes dangerous
and if there is a better option
then always use the better option.”

~ Douglas Crockford

Good to hear:

Rarely, almost never, or never.
A single level is sometimes OK, from a framework base-class such as React.Component.
Favor object composition over class inheritance.

#javascript #js