Design Patterns - Factory Method & Abstract Factory
guillesalazar
1,081 views
15 slides
Oct 10, 2016
Slide 1 of 15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
About This Presentation
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.
Size: 479.45 KB
Language: en
Added: Oct 10, 2016
Slides: 15 pages
Slide Content
Factory Method
& Abstract Factory
Eng. Guillermo Salazar
Co-Founder Senzil S.R.L.
Senior Software Engineer September 2016
Design Pattern Series
1
Why Creational Patterns?
Why is recommended
to Use Creational
Design Patterns?
3 / 15
www.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 / 15
www.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 / 15
www.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 / 15
www.senzil.com
Factory Method - UML
7 / 15
www.senzil.com
Factory Method – Sample Code
Show Java code in Eclipse…
8 / 15
www.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 / 15
www.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 / 15
www.senzil.com
Abstract Factory - UML
11 / 15
www.senzil.com
Abstract Factory – Sample Code
Show Java code in Eclipse…
12 / 15
www.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 / 15
www.senzil.com
Q&A
14 / 15
www.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: [email protected] [email protected]
15 / 15
www.senzil.com