130 likes | 383 Vues
Dependency Injection and Model-View-Controller. Overview. Inversion of Control Model-View-Controller. Why Inversion of Control?. Procedural logic leads to tight coupling to particular implementations Inversion of control pushes logic to the lower application layers
E N D
Overview Inversion of Control Model-View-Controller
Why Inversion of Control? Procedural logic leads to tight coupling to particular implementations Inversion of control pushes logic to the lower application layers Essential coupling remains
Binding to Concrete Instances Factory instantiation Constructor instantiation Configuration based instantiation
Dependency Injection Container Injection Runtime binding Facilitates testing Simpler than factory construction? Looser coupling
Simple Container Example Plug-in Manager Type is requested Lookup for type to be loaded Reflection used to find the type Instantiates an instance and returns it Test and Code use different Data Mapper
Dependency Injection Problems Complex level of indirection Code can be difficult to read and understand Use at component boundaries Level of testing is an economic judgment
Model View Controller Separate user interface from business logic Model has no User Interface interaction Controller handles input events from user interface View represents the appropriate display of the model
Advantages of MVC User interfaces are hard to test Keeps UI level small Makes business logic easier to test UI can be modified without affecting business logic
Summary Inversion of Control minimizes coupling dependency injection for runtime control Model View Controller decouples UI from business logic flexible testing and evolution