DEV Community

Discussion on: Javascript and Classical Inheritance

Collapse
 
jdforsythe profile image
Jeremy Forsythe

Vertical (or classical) inheritance leads to tight coupling. So does dependency injection, which is also used by Angular. That's why you should favor composition over inheritance.

Classes work well in Angular, where every component is a component, but just because it works well in Angular doesn't make it "good" or mean that you should use it unless it's the right tool for the job - and it's probably not most of the time.

Collapse
 
jwp profile image
John Peters • Edited

Fair assessment; however, not all dependency injection or tight coupling is bad.

For example, a Car contains an Engine that is (hopefully) tightly coupled to the bolts that keeps the car able to use the engine.

We rely on the dependency that the gas we buy for our cars was properly mixed, measured and injected into our gas tanks.

Loose coupling is good when we need to "just ensure it works". For example, a bolt breaks off in the engine manifold. We simply drill it out, re-tap the threads and put in a new bolt (maybe a higher grade bolt).

It comes down to using the right tool for the job desired to accomplish.