This presentation explains two design patterns using Java source code. The design patterns used in this presentation are the factory method and abstract factory. You will be able to download java source code.
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
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
12. Abstract Factory – Sample Code
Show Java code in Eclipse…
12 / 15www.senzil.com
13. 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
15. 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