-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
372 lines (333 loc) · 16.8 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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<!DOCTYPE html>
<html>
<head>
<title>From STUPID to SOLID code!</title>
<link rel="stylesheet" href="reveal.js/css/reveal.min.css">
<link rel="stylesheet" href="reveal.js/css/theme/solarized.css" id="theme">
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
<link rel="stylesheet" href="css/custom.css">
<script>
document.write('<link rel="stylesheet" href="reveal.js/css/print/' +
(window.location.search.match(/print-pdf/gi) ? 'pdf' : 'paper') +
'.css" type="text/css" media="print">'
);
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1 class="title">From <strong>STUPID</strong> to <strong>SOLID</strong> code!</h1>
<em>A few basic principles of Object-Oriented Programming and Design.</em>
</section>
<section data-markdown>
<script type="text/template">
# Disclaimer
## These Are Principles, Not Laws!
</script>
</section>
<section>
<section data-markdown>
<script type="text/template">
![](images/shocked-face.jpg)
## **STUPID** code, seriously?
</script>
</section>
<section data-markdown class="highlighted-list">
<script type="text/template">
## What makes code **STUPID**?
* **S**ingleton
* **T**ight Coupling
* **U**ntestability
* **P**remature Optimization
* **I**ndescriptive Naming
* **D**uplication
</script>
</section>
<section data-markdown>
<script type="text/template">
## **S**ingleton
Programs using global state are very difficult to test.
Programs that rely on global state hide their dependencies.
<br>
<br>
<br>
<small>
<a href="https://code.google.com/p/google-singleton-detector/wiki/WhySingletonsAreControversial">
Why Singletons Are Controversial
</a>
<br>
<a href="http://stackoverflow.com/questions/11292109/why-is-singleton-considered-an-anti-pattern-in-java-world-sometimes">
Why is Singleton considered an anti pattern?
</a>
<br>
<a href="http://programmers.stackexchange.com/questions/40373/so-singletons-are-bad-then-what">
So Singletons are bad, then what?
</a>
</small>
</script>
</section>
<section data-markdown>
<script type="text/template">
## **T**ight Coupling
Generalization of the **Singleton** issue.
Also known as **strong coupling**.
<br>
<br>
<br>
<small>
<a href="http://martinfowler.com/ieeeSoftware/coupling.pdf">Reducing Coupling (Martin Fowler)</a>
</small>
</script>
</section>
<section data-markdown>
<script type="text/template">
## **U**ntestability
Testing should not be hard!
Whenever you don't write **unit tests** because you **don't have time**,
the real issue is that your code is bad.
</script>
</section>
<section data-markdown>
<script type="text/template">
## **P**remature Optimization
_Premature optimization is the root of all evil._ — Donald Knuth
There is **only cost** and **no benefit**.
<br>
<br>
<br>
<small>
<a href="http://www.c2.com/cgi/wiki?PrematureOptimization">PrematureOptimization Anti-Pattern</a>
</small>
</script>
</section>
<section data-markdown>
<script type="text/template">
## **I**ndescriptive Naming
Name your classes, methods, attributes, and variables properly.
Don't abbreviate, never!
</script>
</section>
<section data-markdown>
<script type="text/template">
## **D**uplication
**D**on't **R**epeat **Y**ourself!
**K**eep **I**t **S**imple, **S**tupid!
</script>
</section>
</section>
<section data-markdown>
<script type="text/template">
![](images/become-awesome.png)
</script>
</section>
<section>
<section data-markdown>
<script type="text/template">
![](images/borat.jpg)
## **SOLID** to the rescue!
</script>
</section>
<section>
<h1>SOLID</h1>
<p class="left">
A term describing a collection of design principles for <strong>good code</strong>
that was coined by <strong>Robert C. Martin</strong> also known as <strong>Uncle Bob</strong>.
</p>
<p class="right">
<img src="images/books.png" class="no-border" />
</p>
</script>
</section>
<section data-markdown>
<script type="text/template">
# **S**OLID
</script>
</section>
<section data-markdown>
<script type="text/template">
## **S**ingle Responsibility Principle (SRP)
There should **never** be **more than one reason**
<br>for a class to change.
<br>
<br>
<br>
<small>
<a href="http://www.objectmentor.com/resources/articles/srp.pdf">The Single Responsibility Principle</a>
</small>
</script>
</section>
<section>
<img src="images/srp.jpg" />
<p>Just because you can, doesn't mean you should!</p>
</section>
<section data-markdown>
<script type="text/template">
# #protips
* Split big classes
* Use **layers**
* Avoid **god** classes
* Write straightforward comments
</script>
</section>
<section data-markdown>
<script type="text/template">
# S**O**LID
</script>
</section>
<section data-markdown>
<script type="text/template">
## **O**pen/Closed Principle (OCP)
Software entities should be **open for extension**,
<br>but **closed for modification**.
<br>
<br>
<br>
<small>
<a href="http://www.objectmentor.com/resources/articles/ocp.pdf">The Open-Closed Principle</a>
</small>
</script>
</section>
<section data-markdown>
<script type="text/template">
![](images/open-closed.jpg)
</script>
</section>
<section data-markdown>
<script type="text/template">
# #protips
* Make all member variables **private**
* No global variables, ever
* Avoid **setters** (as much as possible)
</script>
</section>
<section data-markdown>
<script type="text/template">
# SO**L**ID
</script>
</section>
<section data-markdown>
<script type="text/template">
## **L**iskov Substitution Principle (LSP)
Objects in a program should be replaceable with instances of their subtypes
**without altering the correctness** of the program.
<br>
<br>
<br>
<small>
<a href="http://c2.com/cgi/wiki?LiskovSubstitutionPrinciple">Liskov Substitution Principle</a>
<br>
<a href="http://www.objectmentor.com/resources/articles/lsp.pdf">The Liskov Substitution Principle</a>
</small>
</script>
</section>
<section data-markdown>
<script type="text/template">
![](images/liskov.jpg)
</script>
</section>
<section data-markdown>
<script type="text/template">
# SOL**I**D
</script>
</section>
<section data-markdown>
<script type="text/template">
## **I**nterface Segregation Principle (ISP)
**Many** client-**specific** interfaces are **better than one**
<br>general-purpose interface.
<br>
<br>
<br>
<small>
<a href="http://www.objectmentor.com/resources/articles/isp.pdf">The Interface Segregation Principle</a>
</small>
</script>
</section>
<section data-markdown>
<script type="text/template">
![](images/interface-segregation.jpg)
</script>
</section>
<section data-markdown>
<script type="text/template">
# SOLI**D**
</script>
</section>
<section data-markdown>
<script type="text/template">
## **D**ependency Inversion Principle (DIP)
High level modules **should not depend upon low level** modules. Both **should depend upon abstractions**.
Abstractions should not depend upon details. Details should depend upon abstractions.
<br>
<br>
<br>
<small>
<a href="http://martinfowler.com/articles/dipInTheWild.html">DIP in the Wild</a>
<br>
<a href="http://www.c2.com/cgi/wiki?DependencyInversionPrinciple">Dependency Inversion Principle</a>
<br>
<a href="http://www.objectmentor.com/resources/articles/dip.pdf">The Dependency Inversion Principle</a>
<br>
<a href="http://lostechies.com/derickbailey/2011/09/22/dependency-injection-is-not-the-same-as-the-dependency-inversion-principle/">
Dependency Injection Is NOT The Same As The Dependency Inversion Principle
</a>
</small>
</script>
</section>
<section data-markdown>
<script type="text/template">
![](images/dip.jpg)
</script>
</section>
</section>
<section data-markdown>
<script type="text/template">
## Conclusion
Avoiding **tight coupling** is the **key**!
Use your brain.
Writing SOLID code is not that hard.
</script>
</section>
<section data-markdown>
<script type="text/template">
## Thank You, Questions?
<br>
<ul class="me">
<li><a href="http://williamdurand.fr" title="website">williamdurand.fr</a></li>
<li><a href="https://github/willdurand" title="github">github.com/willdurand</a></li>
<li><a href="https://twitter.com/couac" title="twitter">twitter.com/couac</a></li>
</ul>
</script>
</section>
<section data-markdown>
<script type="text/template">
## Credits
http://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational-pictures/
</script>
</section>
</div>
</div>
<script type="text/javascript" src="reveal.js/lib/js/head.min.js"></script>
<script type="text/javascript" src="reveal.js/js/reveal.min.js"></script>
<script type="text/javascript">
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme,
transition: Reveal.getQueryHash().transition || 'concave',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
//{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
//{ src: 'reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>