Skip to content

Commit 7cf897a

Browse files
committed
Add presentation for Abstract Factory
1 parent 171c4b3 commit 7cf897a

File tree

4 files changed

+194
-0
lines changed

4 files changed

+194
-0
lines changed

abstract-factory/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ Use the Abstract Factory pattern when
179179

180180
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time.
181181

182+
## Presentations
183+
184+
* [Abstract Factory Pattern](etc/presentation.html)
185+
182186
## Real world examples
183187

184188
* [javax.xml.parsers.DocumentBuilderFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html)

abstract-factory/etc/diagram1.png

56.7 KB
Loading

abstract-factory/etc/diagram2.png

25.7 KB
Loading
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<!--
2+
3+
The MIT License
4+
Copyright (c) 2017 Rodolfo Forte
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
24+
-->
25+
<!DOCTYPE html>
26+
<html>
27+
<head>
28+
<title>Design Patterns - Abstract Factory Presentation</title>
29+
<meta charset="utf-8">
30+
<style>
31+
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
32+
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
33+
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
34+
35+
body { font-family: 'Droid Serif'; }
36+
h1, h2, h3 {
37+
font-family: 'Yanone Kaffeesatz';
38+
font-weight: normal;
39+
}
40+
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
41+
42+
blockquote {
43+
border-left: 0.3em solid rgba(0,0,0,0.5);
44+
padding: 0 15px;
45+
font-style: italic;
46+
}
47+
48+
img {
49+
max-width:100%;
50+
}
51+
</style>
52+
</head>
53+
<body>
54+
<textarea id="source">
55+
56+
class: center, middle
57+
58+
# Abstract Factory
59+
60+
---
61+
62+
# Also known as
63+
64+
* Kit
65+
66+
---
67+
68+
# Intent
69+
70+
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes
71+
72+
---
73+
74+
# Explanation
75+
76+
* [Wikipedia](https://en.wikipedia.org/wiki/Abstract_factory_pattern) says:
77+
> "The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme without specifying their concrete classes"
78+
79+
<br />
80+
81+
* In plain words:
82+
* A factory that groups individual but related/dependent factories together without specifying their concrete classes;
83+
* A factory of factories;
84+
85+
---
86+
87+
# Example
88+
89+
* In a factory that creates kingdoms, we need objects with common theme:
90+
91+
* Elven kingdom needs an Elven king, Elven castle and Elven army;
92+
93+
* Orcish kingdom needs an Orcish king, Orcish castle and Orcish army;
94+
95+
<br />
96+
97+
* There is a dependency between the objects in the kingdom;
98+
99+
---
100+
101+
# Diagram
102+
103+
* Based on the kingdom example, the diagram below showcases the different concrete factories and their concrete products:
104+
105+
.center[![Diagram](diagram1.png)]
106+
107+
108+
---
109+
110+
# Diagram
111+
112+
* The class diagram below showcases the factory of factories;
113+
114+
* At runtime, we can define which Kingdom type is needed and pass it as a parameter to define which concrete KingdomFactory to instantiate;
115+
116+
* The concrete factory returned will then be able to produce the related objects of the specified type;
117+
118+
.center[![Diagram](diagram2.png)]
119+
120+
---
121+
122+
# Applicability
123+
124+
Use the Abstract Factory pattern when:
125+
126+
* A system should be independent of how its products are created, composed and represented;
127+
128+
* A system should be configured with one of multiple families of products;
129+
130+
* A family of related product objects is designed to be used together, and you need to enforce this constraint;
131+
132+
* You want to provide a class library of products, and you want to reveal just their interfaces, not their implementations;
133+
134+
---
135+
136+
# Applicability
137+
138+
Use the Abstract Factory pattern when:
139+
140+
* The lifetime of the dependency is conceptually shorter than the lifetime of the consumer;
141+
142+
* You need a run-time value to construct a particular dependency;
143+
144+
* You want to decide which product to call from a family at runtime;
145+
146+
* You need to supply one or more parameters only known at run-time before you can resolve a dependency;
147+
148+
---
149+
150+
#Use Cases
151+
152+
* Selecting to call the appropriate implementation of FileSystemAcmeService or DatabaseAcmeService or NetworkAcmeService at runtime;
153+
* Unit test case writing becomes much easier;
154+
155+
---
156+
157+
# Consequences
158+
159+
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time
160+
161+
---
162+
163+
# Real world examples
164+
165+
[javax.xml.parsers.DocumentBuilderFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html)
166+
167+
[javax.xml.transform.TransformerFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/transform/TransformerFactory.html#newInstance--)
168+
169+
[javax.xml.xpath.XPathFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance--)
170+
171+
---
172+
173+
# Credits
174+
175+
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
176+
177+
---
178+
179+
# Tutorials
180+
181+
* Source code http://java-design-patterns.com/patterns/abstract-factory/
182+
183+
</textarea>
184+
<script src="https://gnab.github.io/remark/downloads/remark-latest.min.js">
185+
</script>
186+
<script>
187+
var slideshow = remark.create();
188+
</script>
189+
</body>
190+
</html>

0 commit comments

Comments
 (0)