Here’s the Deal
Slant is powered by a community that helps you make informed decisions. Tell us what you’re passionate about to get your personalized feed and help others.
When comparing Dependency Injection vs Inheritance, the Slant community recommends Inheritance for most people. In the question“What are the best Inversion of Control mechanisms? ” Inheritance is ranked 2nd while Dependency Injection is ranked 3rd.
Ranked in these QuestionsQuestion Ranking
Common Questions
Pros
Pro More decoupled code
Since the class doesn't have to know anything about the outside world, everything is more decoupled. If your class would have to fetch its own dependencies then it would have to know where to find them, and as a result, it would have to know about the larger application.
Pro More flexible code
Since your class doesn't have to know about the concrete implementation of the dependencies, it makes them very flexible.
No pros yet!
Cons
Con Steep Learning Curve
Significant effort is needed to grasp DI and use it correctly.
No cons yet!