10
Dependency Injection and Model-View-Controller

Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

Embed Size (px)

Citation preview

Page 1: Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

Dependency Injection and Model-View-Controller

Page 2: Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

Overview

Inversion of ControlModel-View-Controller

Page 3: 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

Essential coupling remains

Page 4: Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

Binding to Concrete Instances

Factory instantiationConstructor instantiationConfiguration based instantiation

Page 5: Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

Dependency Injection

Container InjectionRuntime bindingFacilitates testingSimpler than factory construction?Looser coupling

Page 6: Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

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 

Page 7: Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

Dependency Injection Problems

Complex level of indirectionCode can be difficult to read and understandUse at component boundariesLevel of testing is an economic judgment

Page 8: Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

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

Page 9: Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

Advantages of MVC

User interfaces are hard to testKeeps UI level smallMakes business logic easier to testUI can be modified without affecting business

logic

Page 10: Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller

Summary

Inversion of Controlminimizes couplingdependency injection for runtime control

Model View Controllerdecouples UI from business logicflexible testing and evolution