SlideShare uma empresa Scribd logo
1 de 14
Inversion of Control a design principle Rupesh Bhochhibhoya Software Engineer, Telogical Systems
Inversion of Control, in real life! ,[object Object]
 Hollywood Principle: Don’t call us, we’ll call you.
 Business trips in an organization…  example from  TheServerSide.com [1]Dependency Injection, DI: the word used interchangeably
Inversion of Control, in software Context ,[object Object]
However, components depend with one another to deliver the solution.
Such dependencies among components results the tight coupling.D
Inversion of Control, in software Context … publicclassCameraMan {    StillCamera sCamera;    public void shoot() { sCamera = new StillCamera(); sCamera.action();   } } publicclass StillCamera{ publicvoid action() { System.out.println(“ take Picture");   }	 } publicclassVideoCamera{ publicvoid action() { System.out.println(“video");   }	 }
Inversion of Control, in software Context … publicclassCameraMan {   private Camera camera;   public void shoot(){     camera =  = new StillCamera(); camera.action(); } } publicinterface Camera { publicvoidaction();	 } publicclass StillCamera implements Camera { @Override publicvoid action() { System.out.println(“shoot still picture"); 	}	 }
Inversion of Control, in software Context … publicclassCameraMan {   private Camera camera;  public void setCamera(Camera camera) { this.camera = camera;   }   public void shoot(){ camera.action(); } } publicclassMainClass {   public static void main(String[] args) {      Container container = new Container(); CameraMancMan =container.getComponent(“cameraman”); cMan.shoot(); } } publicclass Container { private Map<String, Object> components; public Container(){ components = newHashMap<String, Object>(); StillCamerasCamera = newStillCamera(); components.put("stillcamera", sCamera); CameraMancMan =  newCameraMan(); cMan.setCamera(sCamera); components.put("cameraman", cMan); } public Object getComponent(String id){ returncomponents.get(id); } } publicinterface Camera { publicvoidaction();	 } publicclass StillCamera implements Camera { @Override   publicvoid action() { System.out.println(“shoot still picture");   }	 }
Inversion of Control, in software Context … Container: actx Component dependency resolution ,[object Object]
Within componentConfiguration management Lifecycle management
Inversion of Control, in software Context … Using Spring framework   publicclassMainClass {    public static void main(String[] args) { ApplicationContentactx = newClassPathXMLApplicationContent(“spring.xml”); CameraMancMan = (CameraMan)actx.getBean(“cameraman”); cMan.click(); } } spring.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns =http://www.springframework.org/schema/beans  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean  id = “cameraman” class = “CameraMan” > <property  name= “camera”  ref=“stillcamera” /> </bean> <bean  id=“stillcamera”   class=“StillCamera” /> </beans>
Inversion of Control, in software Context … <<interface>> Camera <<Assembler>> Container CameraMan spring.xml <creates> StillCamera <creates>

Mais conteúdo relacionado

Mais procurados

Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJSFITC
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Codemotion
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTudor Barbu
 
Node.js exception handling
Node.js exception handlingNode.js exception handling
Node.js exception handlingMinh Hoang
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applicationsMilan Korsos
 
Ignite talks - 自動化的關鍵
Ignite talks - 自動化的關鍵Ignite talks - 自動化的關鍵
Ignite talks - 自動化的關鍵Chen Cheng-Wei
 
JavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and EcosystemJavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and EcosystemAlexander Casall
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
 
JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)Alexander Casall
 
Testing JS with Jasmine
Testing JS with JasmineTesting JS with Jasmine
Testing JS with JasmineEvgeny Gurin
 
Ultimate Node.js countdown: the coolest Application Express examples
Ultimate Node.js countdown: the coolest Application Express examplesUltimate Node.js countdown: the coolest Application Express examples
Ultimate Node.js countdown: the coolest Application Express examplesAlan Arentsen
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialJAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialAnup Singh
 
Test Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsTest Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsNyros Technologies
 
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...GreeceJS
 

Mais procurados (20)

JavaFX Pitfalls
JavaFX PitfallsJavaFX Pitfalls
JavaFX Pitfalls
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabs
 
Node.js exception handling
Node.js exception handlingNode.js exception handling
Node.js exception handling
 
Jasmine with JS-Test-Driver
Jasmine with JS-Test-DriverJasmine with JS-Test-Driver
Jasmine with JS-Test-Driver
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applications
 
Ignite talks - 自動化的關鍵
Ignite talks - 自動化的關鍵Ignite talks - 自動化的關鍵
Ignite talks - 自動化的關鍵
 
JavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and EcosystemJavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and Ecosystem
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)
 
Testing JS with Jasmine
Testing JS with JasmineTesting JS with Jasmine
Testing JS with Jasmine
 
Ultimate Node.js countdown: the coolest Application Express examples
Ultimate Node.js countdown: the coolest Application Express examplesUltimate Node.js countdown: the coolest Application Express examples
Ultimate Node.js countdown: the coolest Application Express examples
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialJAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
Magento++
Magento++Magento++
Magento++
 
Test Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsTest Drive Development in Ruby On Rails
Test Drive Development in Ruby On Rails
 
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
 

Destaque

Anthropology 102, Gisel's Quinceanera
Anthropology 102, Gisel's QuinceaneraAnthropology 102, Gisel's Quinceanera
Anthropology 102, Gisel's Quinceaneradenisemejia91
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentbhochhi
 
Español Grammar Book
Español Grammar BookEspañol Grammar Book
Español Grammar Bookscottiemoe22
 
Live Your Life Purpose
Live Your Life PurposeLive Your Life Purpose
Live Your Life PurposeAaron Black
 
Español Grammar Book
Español Grammar BookEspañol Grammar Book
Español Grammar Bookscottiemoe22
 
Purpose Oriented Leadership
Purpose Oriented LeadershipPurpose Oriented Leadership
Purpose Oriented LeadershipAaron Black
 
Ppt standart variation
Ppt standart variationPpt standart variation
Ppt standart variationMyriam Salas
 
Building Storage for Clouds (ONUG Spring 2015)
Building Storage for Clouds (ONUG Spring 2015)Building Storage for Clouds (ONUG Spring 2015)
Building Storage for Clouds (ONUG Spring 2015)Howard Marks
 
Español Grammar Book
Español Grammar BookEspañol Grammar Book
Español Grammar Bookscottiemoe22
 
Analisiscontenidosuniversidadcercada
AnalisiscontenidosuniversidadcercadaAnalisiscontenidosuniversidadcercada
AnalisiscontenidosuniversidadcercadaEdelin Bravo
 
2015 deploying flash in the data center
2015 deploying flash in the data center2015 deploying flash in the data center
2015 deploying flash in the data centerHoward Marks
 
2015 deploying flash in the data center
2015 deploying flash in the data center2015 deploying flash in the data center
2015 deploying flash in the data centerHoward Marks
 
Roland barthes. lo obvio y lo obtuso
Roland barthes. lo obvio y lo obtusoRoland barthes. lo obvio y lo obtuso
Roland barthes. lo obvio y lo obtusoEdelin Bravo
 

Destaque (17)

P O
P  OP  O
P O
 
Anthropology 102, Gisel's Quinceanera
Anthropology 102, Gisel's QuinceaneraAnthropology 102, Gisel's Quinceanera
Anthropology 102, Gisel's Quinceanera
 
Proyecto final
Proyecto finalProyecto final
Proyecto final
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Español Grammar Book
Español Grammar BookEspañol Grammar Book
Español Grammar Book
 
Live Your Life Purpose
Live Your Life PurposeLive Your Life Purpose
Live Your Life Purpose
 
Español Grammar Book
Español Grammar BookEspañol Grammar Book
Español Grammar Book
 
Purpose Oriented Leadership
Purpose Oriented LeadershipPurpose Oriented Leadership
Purpose Oriented Leadership
 
Animals
AnimalsAnimals
Animals
 
Leigh winterbottom portfolio
Leigh winterbottom portfolioLeigh winterbottom portfolio
Leigh winterbottom portfolio
 
Ppt standart variation
Ppt standart variationPpt standart variation
Ppt standart variation
 
Building Storage for Clouds (ONUG Spring 2015)
Building Storage for Clouds (ONUG Spring 2015)Building Storage for Clouds (ONUG Spring 2015)
Building Storage for Clouds (ONUG Spring 2015)
 
Español Grammar Book
Español Grammar BookEspañol Grammar Book
Español Grammar Book
 
Analisiscontenidosuniversidadcercada
AnalisiscontenidosuniversidadcercadaAnalisiscontenidosuniversidadcercada
Analisiscontenidosuniversidadcercada
 
2015 deploying flash in the data center
2015 deploying flash in the data center2015 deploying flash in the data center
2015 deploying flash in the data center
 
2015 deploying flash in the data center
2015 deploying flash in the data center2015 deploying flash in the data center
2015 deploying flash in the data center
 
Roland barthes. lo obvio y lo obtuso
Roland barthes. lo obvio y lo obtusoRoland barthes. lo obvio y lo obtuso
Roland barthes. lo obvio y lo obtuso
 

Semelhante a Inversion Of Control

04b swing tutorial
04b swing tutorial04b swing tutorial
04b swing tutorialRobert Wolf
 
Naive application development
Naive application developmentNaive application development
Naive application developmentShaka Huang
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with exampleshadabgilani
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklum Ukraine
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Codemotion
 
Flash Security, OWASP Chennai
Flash Security, OWASP ChennaiFlash Security, OWASP Chennai
Flash Security, OWASP Chennailavakumark
 
Robotlegs on Top of Gaia
Robotlegs on Top of GaiaRobotlegs on Top of Gaia
Robotlegs on Top of GaiaJesse Warden
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeNaresh Jain
 
Rits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce LightningRits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce LightningRight IT Services
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera ArchitecturePicker Weng
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in detailsMax Klymyshyn
 
Forcetree.com writing a java program to connect to sfdc
Forcetree.com writing  a java program to connect  to sfdcForcetree.com writing  a java program to connect  to sfdc
Forcetree.com writing a java program to connect to sfdcEdwin Vijay R
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0Matt Raible
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Ahmed Moawad
 

Semelhante a Inversion Of Control (20)

java swing tutorial for beginners(java programming tutorials)
java swing tutorial for beginners(java programming tutorials)java swing tutorial for beginners(java programming tutorials)
java swing tutorial for beginners(java programming tutorials)
 
04b swing tutorial
04b swing tutorial04b swing tutorial
04b swing tutorial
 
04b swing tutorial
04b swing tutorial04b swing tutorial
04b swing tutorial
 
Spring Framework - III
Spring Framework - IIISpring Framework - III
Spring Framework - III
 
Naive application development
Naive application developmentNaive application development
Naive application development
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with example
 
Os Haase
Os HaaseOs Haase
Os Haase
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
 
Flash Security, OWASP Chennai
Flash Security, OWASP ChennaiFlash Security, OWASP Chennai
Flash Security, OWASP Chennai
 
Robotlegs on Top of Gaia
Robotlegs on Top of GaiaRobotlegs on Top of Gaia
Robotlegs on Top of Gaia
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Rits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce LightningRits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce Lightning
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera Architecture
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
 
Forcetree.com writing a java program to connect to sfdc
Forcetree.com writing  a java program to connect  to sfdcForcetree.com writing  a java program to connect  to sfdc
Forcetree.com writing a java program to connect to sfdc
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 

Inversion Of Control

  • 1. Inversion of Control a design principle Rupesh Bhochhibhoya Software Engineer, Telogical Systems
  • 2.
  • 3. Hollywood Principle: Don’t call us, we’ll call you.
  • 4. Business trips in an organization… example from TheServerSide.com [1]Dependency Injection, DI: the word used interchangeably
  • 5.
  • 6. However, components depend with one another to deliver the solution.
  • 7. Such dependencies among components results the tight coupling.D
  • 8. Inversion of Control, in software Context … publicclassCameraMan { StillCamera sCamera; public void shoot() { sCamera = new StillCamera(); sCamera.action(); } } publicclass StillCamera{ publicvoid action() { System.out.println(“ take Picture"); } } publicclassVideoCamera{ publicvoid action() { System.out.println(“video"); } }
  • 9. Inversion of Control, in software Context … publicclassCameraMan { private Camera camera; public void shoot(){ camera = = new StillCamera(); camera.action(); } } publicinterface Camera { publicvoidaction(); } publicclass StillCamera implements Camera { @Override publicvoid action() { System.out.println(“shoot still picture"); } }
  • 10. Inversion of Control, in software Context … publicclassCameraMan { private Camera camera; public void setCamera(Camera camera) { this.camera = camera; } public void shoot(){ camera.action(); } } publicclassMainClass { public static void main(String[] args) { Container container = new Container(); CameraMancMan =container.getComponent(“cameraman”); cMan.shoot(); } } publicclass Container { private Map<String, Object> components; public Container(){ components = newHashMap<String, Object>(); StillCamerasCamera = newStillCamera(); components.put("stillcamera", sCamera); CameraMancMan = newCameraMan(); cMan.setCamera(sCamera); components.put("cameraman", cMan); } public Object getComponent(String id){ returncomponents.get(id); } } publicinterface Camera { publicvoidaction(); } publicclass StillCamera implements Camera { @Override publicvoid action() { System.out.println(“shoot still picture"); } }
  • 11.
  • 13. Inversion of Control, in software Context … Using Spring framework publicclassMainClass { public static void main(String[] args) { ApplicationContentactx = newClassPathXMLApplicationContent(“spring.xml”); CameraMancMan = (CameraMan)actx.getBean(“cameraman”); cMan.click(); } } spring.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns =http://www.springframework.org/schema/beans xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id = “cameraman” class = “CameraMan” > <property name= “camera” ref=“stillcamera” /> </bean> <bean id=“stillcamera” class=“StillCamera” /> </beans>
  • 14. Inversion of Control, in software Context … <<interface>> Camera <<Assembler>> Container CameraMan spring.xml <creates> StillCamera <creates>
  • 15. Ways to implement IoC IoC DI Constructor injection Setter injection Interface injection
  • 16. Ways to implement IoC publicclassCameraMan { private Camera camera; public void setCamera(Camera camera) { this.camera = camera; } } IoC publicclass Container { private Map<String, Object> components; public Container(){ components = newHashMap<String, Object>(); StillCamerasCamera = newStillCamera(); components.put("stillcamera", sCamera); CameraMancMan = newCameraMan(); cMan.setCamera(sCamera); components.put("cameraman", cMan); } public Object getComponent(String id){ returncomponents.get(id); } } DI Setter injection Interface injection Constructor injection Spring.xml … <bean id = “cameraman” class = “CameraMan” > <property name= “camera” ref=“stillcamera” /> </bean> <bean id=“stillcamera” class=“StillCamera” /> …
  • 17. Ways to implement IoC publicclassCameraMan { private Camera camera; public CameraMan(Camera cam){ this.camera = cam; } } IoC publicclass Container { private Map<String, Object> components; public Container(){ components = newHashMap<String, Object>(); StillCamerasCamera = newStillCamera(); components.put("stillcamera", sCamera); CameraMancMan = new CameraMan(sCamera);components.put("cameraman", cMan); } public Object getComponent(String id){ returncomponents.get(id); } } DI Constructor injection … <bean id = “cameraman” class = “CameraMan” > <constructor-arg> <bean ref=“stillcamera"/> </constructor-arg> </bean> <bean id=“stillcamera” class=“StillCamera” /> … Setter injection Interface injection Spring.xml
  • 18. Ways to implement IoC publicinterfaceInjectable{ publicvoidinject(Map<String, Object> component); } IoC publicclassCameraMan implementsInjectable { private Camera camera; public void inject(Map<String, Object> components){ camera = (Camera) components.get(“stillcamera”); } } DI publicclass Container { private Map<String, Object> components; public Container(){ components = newHashMap<String, Object>(); StillCamerasCamera = newStillCamera(); components.put("stillcamera", sCamera); CameraMancMan = newCameraMan(); cMan.inject(components); } public Object getComponent(String id){ returncomponents.get(id); } } Setter injection Interface injection Constructor injection

Notas do Editor

  1. About myself and company- my aim in this presentation is to make you aware of IoC , by illustrating the design problem and learn how we can resolve the problem utilizing frameworks that implments IoC
  2. what does it actually mean? Some of us may first end up with very puzzled. -- You go the bar and ask for the beer. You don’t tell bartender what kind of beer. So, bartender come back with bud light, coor light or heineken. -Question is what part of aspect of control are being inverted. - If your goal is to build is house, you shouldn’t be worried about how to manufacture hardware and other materials. They will be provided when needed. -- IoC works same way, A component such as DataStore can specify that it requires a DAO, and later be passed one when it is needed. If the DataStore specified that it wished to use a database-aware component, it would be totally controlling the type of object it would be using. However, by allowing the container to choose one for it, it is delegating its control. (Hence “ Inversion of Control”)-- Travelling by air you or your colleagues in an organization, need to arrange following…Decide the destination, arrival date and time.Call up airline agency for flight bookingCall up rental/cab agency for scheduling pickup/drop off --- Company decided to use another agencies, you and all other colleague has to relearn how to make contact and their mechanisms. --- New protocol: company created an administrative department, you are use IVR system where you simply state destination, dates and time, your flight reservations are made, cab is scheduled for time and ticket delivered to you. Now if preferred agencies were changed, administration dept. would become aware of a change, would perhaps readjust its workflow and IVR system could be reprogrammed but way we interact with IVR remains same. –see how dependency injection is done here!!
  3. The biggest problem is that CameraMan class controls the creation of StillCamera object Moreover direct reference to StillCamera class leads to tight coupling between CameraMan and StillCamera
  4. Free from object reference but still tight with control of creating StillCamera object.
  5. This is where we completely inversion the control of creating the objects referred by the components by deligating lookup functionality and injecting dependencies to Container class- Hence, container class implemented the Inversion of control. Container is responsible for injecting the necessary resources into each component.Note as early I have stated, the component has to communicate with another component to accomplish the job in hand. A common issue to deal with is how to wire together different elements. So, at somepoint somehow somewhere, there should would be a component that creates and manages components: such components is call container. We created Container class to dump all the complexities and make other components reusable and lightweighted.
  6. By using container framework that implements IoC, I mean that follow dependency pattern, we achieved three major advantanges.
  7. Spring framework implements IoC principle by using Dependency Injection pattern. Here in example we are using xml-based Spring container to create, manage and inject the dependency components/objectsOnce, container take care of all contructions and managemnt of objects/component, we can focus more on implementations: The solution shifts the object creation control from CameraMan class to some one else.
  8. The basic idea for the Dependency Injection is to have a separate component/object, an assembler, that populates a field in the CameraMan class with an appropriate implementation for the camera interface.
  9. As stated before, IoC is the design principle and DI is the design pattern, way to implement the IoC. There are three ways of implementing IoC using DIOther way of implementations: Factory patternService locator, Sun’s core Java EE design patterns
  10. The most popular one. container injects the dependency via setter method declared in a component.
  11. Here dependencies are inject via a constructor. Support by most IoC container including Spring. avoids problem posed by setter injection, as all dependencies has to be provided in the constructor arguments list, so impossible to miss. once injected, can’t be modified, preventing careless modification problem. Shortcoming: JVM unable to add default constructor, explicit definition required if needed. when dependencies is high, long list of constructor arguments reduce readablity of code.
  12. Among three types of injection, interface injection is rarely or seldom used. To apply it, component must implement a particular interface defined by the container, so that the container can inject dependencies via the interface. ShortComing: requires all the components must implement a particular interface for container to inject dependencies. Since interface is container specific, components have to rely on the container and cannot be reused outside its scope