Spring
Framework &
Inversion of
Control

By Nazim Sitmanbetov
Preconditions
 Keep

calm
 Sit back
 Relax
Inversion of Control
 OOP

principle, not design pattern
 One of
Principle in OOP
 Modules

depend on abstractions
 Low level modules do not depend on
high level modules
Modules depend on
abstractions
Bad

Good
Low level modules do not
depend on high level modules
Bad

Tip: Avoid cyclic dependencies

Good
IoC implementations
 Factory

Method
 Service Locator
 Dependency Injection (DI)
Factory Method
Service Locator
Dependency Injection
 Allow

client of module to set dependency

Module

Client
Achievement unlocked
Framework
 Java
 Light-weight
 Open

Source
What means Light-Weight?
 No

container requirements
 Quick start
 Application easy-to-test
Spring & IoC
 Dependency

Injection
 Service Locator
Spring & Dependency
Injection
XML Based Configuration
mcdonalds-with-kazatin.xml

Java Program
Spring & Service Locator
Annotation Based
mcdonalds-locator.xml
Spring & Service Locator
Dependency Injection vs
Service Locator
DI

Service Locator

• Imperative
• Can be used with
existing classes

• Declarative
• Need to modify
existing classes
Spring components
Time to cook

Spring framework & inversion of control