Factory Method & Abstract Factory Eng. Guillermo Salazar Co-Founder Senzil S.R.L. Senior Software Engineer September 2016 Design Pattern Series 1
Agenda • Why Creational Patterns? • Factory Method – Purpose / Applies When… – UML – Sample in Java • Abstract Factory – Purpose / Applies When… – UML – Sample in Java • Summary • Q & A 2 / 15www.senzil.com
Why Creational Patterns? Why is recommended to Use Creational Design Patterns? 3 / 15www.senzil.com
Why Creational Patterns? – Abstract the instantiation process (it sometimes could be very complicated) – Encapsulate knowledge about which concrete classes the system is using. – Flexible the what, who, how and when the object are created. – Be an independent the way create, compose, and represent the objects. TO 4 / 15www.senzil.com
Factory Method - Purpose It defines an interface to create an object, but it does not create the object. It delegates on all subclasses, which object will be created. This class (an interface or an abstract class) does NOT know about any concrete class (only the super class). 5 / 15www.senzil.com
Factory Method - Applies when… • You have more than one class sharing the same parent class. • It is not possible to know, the concrete class to create in the compile time. • You do NOT want to have infinite statements IF / ELSE to create objects. 6 / 15www.senzil.com
Factory Method - UML 7 / 15www.senzil.com
Factory Method – Sample Code Show Java code in Eclipse… 8 / 15www.senzil.com
Abstract Factory - Purpose • It defines an interface to create object's families, but it doesn't create the objects. • The objects are called family, because all of them are related. • This class (an interface or an abstract class) does NOT know about any concrete class (only the super class). 9 / 15www.senzil.com
Abstract Factory - Applies when… • It is not possible to know, the concrete class to create in the compile time. • The objects family are done to be managed together. It must be fulfilled, and allow us to be consistent when we use the objects. 10 / 15www.senzil.com
Abstract Factory - UML 11 / 15www.senzil.com
Abstract Factory – Sample Code Show Java code in Eclipse… 12 / 15www.senzil.com
Summary – Creational Design Patterns • They are used and created to deal with object creation mechanisms, trying to create objects in a manner suitable depending on the situation. • It allows us to have a flexible design when we need to do a change in our source code. 13 / 15www.senzil.com
Q&A 14 / 15www.senzil.com
Thank You For Your Attention! If you have questions, you can contact me: bitbucket.org/salazarguille/design_patterns You can get the source code in the below URL: guillermo@senzil.com guillesalazar@gmail.com 15 / 15www.senzil.com

Design Patterns - Factory Method & Abstract Factory

  • 1.
    Factory Method & AbstractFactory Eng. Guillermo Salazar Co-Founder Senzil S.R.L. Senior Software Engineer September 2016 Design Pattern Series 1
  • 2.
    Agenda • Why CreationalPatterns? • Factory Method – Purpose / Applies When… – UML – Sample in Java • Abstract Factory – Purpose / Applies When… – UML – Sample in Java • Summary • Q & A 2 / 15www.senzil.com
  • 3.
    Why Creational Patterns? Whyis recommended to Use Creational Design Patterns? 3 / 15www.senzil.com
  • 4.
    Why Creational Patterns? –Abstract the instantiation process (it sometimes could be very complicated) – Encapsulate knowledge about which concrete classes the system is using. – Flexible the what, who, how and when the object are created. – Be an independent the way create, compose, and represent the objects. TO 4 / 15www.senzil.com
  • 5.
    Factory Method -Purpose It defines an interface to create an object, but it does not create the object. It delegates on all subclasses, which object will be created. This class (an interface or an abstract class) does NOT know about any concrete class (only the super class). 5 / 15www.senzil.com
  • 6.
    Factory Method -Applies when… • You have more than one class sharing the same parent class. • It is not possible to know, the concrete class to create in the compile time. • You do NOT want to have infinite statements IF / ELSE to create objects. 6 / 15www.senzil.com
  • 7.
    Factory Method -UML 7 / 15www.senzil.com
  • 8.
    Factory Method –Sample Code Show Java code in Eclipse… 8 / 15www.senzil.com
  • 9.
    Abstract Factory -Purpose • It defines an interface to create object's families, but it doesn't create the objects. • The objects are called family, because all of them are related. • This class (an interface or an abstract class) does NOT know about any concrete class (only the super class). 9 / 15www.senzil.com
  • 10.
    Abstract Factory -Applies when… • It is not possible to know, the concrete class to create in the compile time. • The objects family are done to be managed together. It must be fulfilled, and allow us to be consistent when we use the objects. 10 / 15www.senzil.com
  • 11.
    Abstract Factory -UML 11 / 15www.senzil.com
  • 12.
    Abstract Factory –Sample Code Show Java code in Eclipse… 12 / 15www.senzil.com
  • 13.
    Summary – CreationalDesign Patterns • They are used and created to deal with object creation mechanisms, trying to create objects in a manner suitable depending on the situation. • It allows us to have a flexible design when we need to do a change in our source code. 13 / 15www.senzil.com
  • 14.
  • 15.
    Thank You ForYour Attention! If you have questions, you can contact me: bitbucket.org/salazarguille/design_patterns You can get the source code in the below URL: guillermo@senzil.com guillesalazar@gmail.com 15 / 15www.senzil.com