Upload
laurence-newton
View
215
Download
2
Embed Size (px)
Citation preview
Dependency Injection and Model-View-Controller
Overview
Inversion of ControlModel-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 instantiationConstructor instantiationConfiguration based instantiation
Dependency Injection
Container InjectionRuntime bindingFacilitates testingSimpler than factory construction?Looser coupling
Simple Container Example
Plug-in ManagerType is requestedLookup for type to be loadedReflection used to find the typeInstantiates an instance and returns itTest and Code use different Data Mapper
Dependency Injection Problems
Complex level of indirectionCode can be difficult to read and understandUse at component boundariesLevel of testing is an economic judgment
Model View Controller
Separate user interface from business logicModel has no User Interface interactionController handles input events from user
interfaceView represents the appropriate display of the
model
Advantages of MVC
User interfaces are hard to testKeeps UI level smallMakes business logic easier to testUI can be modified without affecting business
logic
Summary
Inversion of Controlminimizes couplingdependency injection for runtime control
Model View Controllerdecouples UI from business logicflexible testing and evolution