際際滷

際際滷Share a Scribd company logo
Spring:
 usarlo conviene, ma usalo bene
                       Lucio Benfante
                    lucio@benfante.com




verona.javaday.it                        www.jugpadova.it
Inversion Of Control (IoC)


Inversion of control, or IoC, is an abstract
principle describing an aspect of some
software architecture designs in which the
flow of control of a system is inverted in
comparison to procedural programming.

                            from wikipedia
Dependencies are BAD




List drugs = new ArrayList();
IoC and Dependency Injection (DI)
                    Inversion of Control




     Dependency Lookup                  Dependency Injection




                     Setter injection               Constructor Injection
Spring framework?




IoC container
Inject your objects

<beans>

 <bean id=person1 class=com.myapp.Person>
  <property name=firstName value=Lucio/>
  <property name=lastName value=Benfante/>
  <property name=bornIn ref=venice/>
 </bean>

 <bean id=venice class=com.myapp.City>
  <constructor-arg value=Venezia/>
 </bean>

</beans>
XML is boring
Spring in Parancoe demonstration
       (www.parancoe.org)
References
   http://www.objectmentor.com/resources/articles/dip.pdf
   http://martinfowler.com/articles/injection.html
   http://martinfowler.com/bliki/InversionOfControl.html
   www.springframework.org
   www.parancoe.org

More Related Content

Spring: usarlo conviene, ma usalo bene!

  • 1. Spring: usarlo conviene, ma usalo bene Lucio Benfante lucio@benfante.com verona.javaday.it www.jugpadova.it
  • 2. Inversion Of Control (IoC) Inversion of control, or IoC, is an abstract principle describing an aspect of some software architecture designs in which the flow of control of a system is inverted in comparison to procedural programming. from wikipedia
  • 3. Dependencies are BAD List drugs = new ArrayList();
  • 4. IoC and Dependency Injection (DI) Inversion of Control Dependency Lookup Dependency Injection Setter injection Constructor Injection
  • 6. Inject your objects <beans> <bean id=person1 class=com.myapp.Person> <property name=firstName value=Lucio/> <property name=lastName value=Benfante/> <property name=bornIn ref=venice/> </bean> <bean id=venice class=com.myapp.City> <constructor-arg value=Venezia/> </bean> </beans>
  • 8. Spring in Parancoe demonstration (www.parancoe.org)
  • 9. References http://www.objectmentor.com/resources/articles/dip.pdf http://martinfowler.com/articles/injection.html http://martinfowler.com/bliki/InversionOfControl.html www.springframework.org www.parancoe.org