Published Sep 3, 2019

Episode 2: Dependencies

Markus Völter and Eberhard Wolff delve into the complexities of managing dependencies in object-oriented programming, contrasting factory patterns with dependency injection to unveil strategies for enhancing software modularity, flexibility, and testability through model-driven solutions and customized factories.
Episode Highlights
Software Engineering Radio - the podcast for professional software developers logo

Popular Clips

Episode Highlights

  • Dependency Injection

    Dependency injection is a powerful technique that allows objects to declare their dependencies, which are then provided by an external container. explains that this method offers three levels of flexibility: knowing the interface, knowing the implementation, and configuring runtime instances 1. This flexibility is achieved through various techniques like constructor parameters, setter methods, and attributes, which are common in object-oriented programming 1. highlights the popularity of Spring as a dependency injection container, noting its ability to support multiple techniques such as auto-wiring by type or name 2.

       

    Testing Benefits

    Dependency injection significantly enhances software testability by allowing for better isolation and flexibility. emphasizes that it enables real unit tests by isolating classes and easily swapping subsystems for testing purposes 3. This approach not only supports unit tests but also facilitates integration tests by allowing different configurations and environments 3. Wolff argues that the primary advantage of dependency injection is testability, rather than flexibility or reusability 4.

       

    Factory vs. DI

    The debate between factory patterns and dependency injection centers on control and flexibility. notes that while factories can centralize object creation, they often lead to global access issues, making dependency injection a more controlled alternative 5. acknowledges that dependency injection may initially seem like "magic," but it ultimately aligns with the broader trend in software development of relinquishing control for modularity 6. He suggests that model-driven approaches can complement dependency injection by specifying dependencies in models like UML diagrams 7.

Related Episodes