-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·341 lines (305 loc) · 12.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Introduction to Design Patterns</title>
<meta name="author" content="David Stanley">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/night.css" id="theme">
<link rel="stylesheet" href="style.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<!-- Begin Introduction -->
<section>
<h1>Introduction to Design Patterns</h1>
<h6>Solving common problems with common solutions</h6>
</section>
<section>
<img src="img/ds.jpg" />
<h2>David Stanley</h2>
<ul>
<li>Technical Architect for MMGY Global</li>
<li>10 years in software engineering</li>
<li>@davidstanley01</li>
</ul>
</section>
<section>
<section>
<h2>Assumptions and Disclaimers</h2>
<ul>
<li class="fragment">UML and code samples from https://github.com/domnikl/DesignPatternsPHP</li>
<li class="fragment">This is only an introduction</li>
<li class="fragment">We only have about 45 minutes</li>
</ul>
</section>
</section>
<section>
<section>
<h2>Outline</h2>
<ul>
<li class="fragment">Common Language</li>
<li class="fragment">SOLID and DRY</li>
<li class="fragment">Common Patterns</li>
<li class="fragment">Questions</li>
</ul>
</section>
</section>
<!-- End Intro -->
<!-- Begin Common Language -->
<section>
<section>
<h2>Common Language</h2>
<ul>
<li class="fragment">In the world of software, a pattern is a tangible manifestation of an organization’s tribal memory. —Grady Booch in Core J2EE Patterns</li>
<li class="fragment">[A pattern is] a solution to a problem in a context. —The Gang of Four, Design Patterns: Elements of Reusable Object-Oriented Software</li>
</ul>
</section>
<section>
<ul>
<li class="fragment">Language independent</li>
<li class="fragment">Define a problem</li>
<li class="fragment">Define a solution</li>
<li class="fragment">Provide a common language for collaborating</li>
</ul>
</section>
<section>
<h2>Three Basic Types</h2>
<ul>
<li class="fragment">Structural</li>
<li class="fragment">Behavioral</li>
<li class="fragment">Creational</li>
</ul>
</section>
</section>
<!-- End Common Language -->
<!-- Begin SOLID & DRY -->
<section>
<section>
<h2>SOLID & DRY</h2>
</section>
<section>
<h2>S - Single Responsibility Principle</h2>
<p>A class should have one and only one responsibility.</p>
<pre><code>
use Illuminate\Support\ServiceProvider;
class EventServiceProvider extends ServiceProvider {
public function register() {
$this->app['events'] = $this->app->share(function($app) {
return new Dispatcher($app);
});
}
}
</code></pre>
</section>
<section>
<h2>O - Open/Closed Principle</h2>
<p>A class should be open for extension, but closed for modification.</p>
<pre><code>
use Stanley\Example\PartInterface;
use Illuminate\Support\Collection;
public function getTotal(Collection $parts) {
return $parts->reduce(function(PartInterface $part) {
return $part->getPrice();
});
}
</code></pre>
</section>
<section>
<h2>L - Liskov Substitution Principle</h2>
<p>Objects should replaceable with instances of their subtypes.</p>
<pre><code>
abstract class Exam {
abstract public function score();
}
class Quiz extends Exam {
public function score() {
return "100";
}
}
class Grade {
protected $scores;
public function calculate(Exam $exam) {
$this->scores += $exam->score();
}
}
</code></pre>
</section>
<section>
<h2>I - Interface Segregation</h2>
<p>A client should not be forced to implement methods that it doesn't use.</p>
</section>
<section>
<h2>D - Dependency Inversion</h2>
<p>Abstractions should not depend upon details. Details should depend upon abstractions.</p>
</section>
<section>
<h2>DRY</h2>
<ul>
<li class="fragment">Don't Repeat Yourself</li>
</ul>
</section>
</section>
<!-- End SOLID & DRY -->
<!-- Begin Examples -->
<section>
<section>
<h2>Examples</h2>
<ul>
<li class="fragment">Singleton</li>
<li class="fragment">Observer</li>
<li class="fragment">Factory Method</li>
<li class="fragment">Dependency Injection</li>
</ul>
</section>
</section>
<!-- End Examples -->
<!-- Begin Singleton -->
<section>
<section>
<h2>Singleton</h2>
<img src="/img/highlander_movie.jpeg" />
</section>
<section>
<h2>Singleton - The Problem</h2>
<ul>
<li class="fragment">Sometimes, we think we need near-global access to an object or a set of values without using global variables.</li>
<li class="fragment">Further, sometimes we need to ensure that all parts of our application use one, and only one, instance of a class.</li>
</ul>
</section>
<section>
<h2>Singleton - The Implementation</h2>
<img src="/img/singleton_uml.png" />
</section>
<section>
<h2>Singleton - Consequences</h2>
<ul>
<li class="fragment">Can make it tougher to test</li>
<li class="fragment">Can make it tougher to debug</li>
<li class="fragment">Easy to over-use</li>
</ul>
</section>
</section>
<!-- End Singleton -->
<!-- Begin Observer -->
<section>
<section>
<h2>Observer</h2>
</section>
<section>
<h2>Observer - The Problem</h2>
<ul>
<li class="fragment">Business rules dictate that when a certain value changes or the system completes a specific action, then multiple other actions must occur.</li>
<li class="fragment">When new user registers, start a session, write data to db, send welcome email, create s3 bucket, etc.</li>
<li class="fragment">Just before a model is updated, write the old row data to an audit table.</li>
</ul>
</section>
<section>
<h2>Observer - The Implementation</h2>
<img src="/img/observer_uml.png" />
</section>
<section>
<h2>Observer - Benefits</h2>
<ul>
<li class="fragment">Promotes loose coupling of components</li>
<li class="fragment">Can add/remove listeners very easily</li>
<li class="fragment">In this example, concrete objects depend upon abstractions, satisfying the Dependency Inversion principle</li>
</ul>
</section>
</section>
<!-- End Observer -->
<!-- Begin Factory Method -->
<section>
<section>
<h2>Factory Method</h2>
</section>
<section>
<h2>Factory Method - The Problem</h2>
<ul>
<li class="fragment">Object creation is a pain.</li>
<li class="fragment">Sometimes, we don't know what type of object we need until run-time</li>
</ul>
</section>
<section>
<h2>Factory Method - The Implementation</h2>
<img src="/img/factory_method_uml.png" />
</section>
<section>
<h2>Factory Method - Benefits</h2>
<ul>
<li class="fragment">We've removed object creation to a specialized class</li>
<li class="fragment">Grouping the creation of similar objects into a single process promotes code re-use</li>
<li class="fragment">In this example, concrete objects depend upon abstractions, satisfying the Dependency Inversion principle</li>
</ul>
</section>
</section>
<!-- End Factory Method -->
<!-- Begin Dependency Injection -->
<section>
<section>
<h2>Dependency Injection</h2>
</section>
<section>
<h2>Dependency Injection - The Problem</h2>
<ul>
<li class="fragment">Configuration values (db user, db password, etc) are often needed within classes</li>
</ul>
</section>
<section>
<h2>Dependency Injection - The Implementation</h2>
<img src="/di_uml.png" />
</section>
<section>
<h2>Dependency Injection - Benefits</h2>
<ul>
<li class="fragment">Improves testability</li>
<li class="fragment">Improves clarity of code</li>
<li class="fragment">For me, forces me to think about what the class is doing</li>
</ul>
</section>
</section>
<!-- End Dependency Injection -->
<section>
<h2>Questions?</h2>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'fade', // default/cube/page/concave/zoom/linear/fade/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>