-
Notifications
You must be signed in to change notification settings - Fork 2
/
slides.html
491 lines (472 loc) · 25.2 KB
/
slides.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<!DOCTYPE html>
<html>
<head>
<title>Better Ruby</title>
<meta charset='utf-8' />
<meta content='width=1024, user-scalable=no' name='viewport' />
<!-- deck.js's core css -->
<link href="deck.js/core/deck.core.css" rel="stylesheet" type="text/css"/>
<!-- deck.js extension CSS files -->
<link href="deck.js/extensions/codemirror/deck.codemirror.css" rel="stylesheet" type="text/css"/>
<link href="deck.js/extensions/goto/deck.goto.css" rel="stylesheet" type="text/css"/>
<link href="deck.js/extensions/hash/deck.hash.css" rel="stylesheet" type="text/css"/>
<link href="deck.js/extensions/menu/deck.menu.css" rel="stylesheet" type="text/css"/>
<link href="deck.js/extensions/navigation/deck.navigation.css" rel="stylesheet" type="text/css"/>
<link href="deck.js/extensions/scale/deck.scale.css" rel="stylesheet" type="text/css"/>
<link href="deck.js/extensions/status/deck.status.css" rel="stylesheet" type="text/css"/>
<!-- all css in the css dir: Keydown CSS, your custom CSS, and themes from deck.js -->
<link href="css/keydown.css" rel="stylesheet" type="text/css"/>
<link href="css/better_ruby_mtn_west.css" rel="stylesheet" type="text/css"/>
<link href="css/default.css" rel="stylesheet" type="text/css"/>
<link href="css/horizontal-slide.css" rel="stylesheet" type="text/css"/>
<link href="css/swiss.css" rel="stylesheet" type="text/css"/>
<!-- Modernizr (provided for legacy browsers) -->
<script src="deck.js/support/modernizr.custom.js" type="text/javascript"></script>
</head>
<body class='deck-container keydown'>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Better Ruby</h1>
<h2>Through Design Principles*</h2>
<h3>Mike Gehard</h3>
<h3><a href="https://twitter.com/#!/mikegehard">@mikegehard</a></h3>
<h3><a href="https://github.com/msgehard/Better-Ruby-Through-Design-Patterns">https://github.com/msgehard/Better-Ruby-Through-Design-Patterns</a></h3>
<h5>* Bonus points to anyone who can name the musical reference</h5>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><img src="images/fatboyslim.jpg" alt="Fatboy Slim, Better Living Through Chemistry" /></p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='bottom-left full-background livingsocial slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Tech Lead - User Acquisition</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>"Nothing endures but change."</h1>
<h4>Heraclitus of Ephesus (c.535 BC - 475 BC)</h4>
<p><img src="images/Heraclitus.jpg" alt="Heraclitus of Ephesus (c.535 BC - 475 BC)" /></p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>That's great but how does that apply to Ruby?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>When did you last build an application that didn't change?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>How is your app going to adjust to change?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><img src="images/hasbro-jenga.jpg" alt="Jenga" /></p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='full-background remodelChurch slide'>
<div class='spacer top'></div>
<div class='content'>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>What decides how your app is going to withstand change?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='bottom-left design full-background slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>The design</h1>
</div>
<div class='spacer bottom'></div>
<div class='attribution flickr'>
<a href='http://www.flickr.com/people/span112/' target='_blank'>span112</a>
</div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><img src="images/designStaminaGraph.gif" alt="Design Stamina Graph" />
<a href="http://martinfowler.com/bliki/DesignStaminaHypothesis.html">http://martinfowler.com/bliki/DesignStaminaHypothesis.html</a></p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='bottom-left full-background rails slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>I'm using Rails so I don't need to do design.</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><textarea class='code' display='none' mode='ruby'>class Post < ActiveRecord::Base

 has_many :comments
 belongs_to :author

 after_update :alert_updated

 def approve!
 update_attribute(:approved, true)
 end

 def attribute_to(user)
 update_attribute(:author, user)
 end

 private
 def alert_updated
 # tell everyone that the post was updated
 # and what changed via email
 end

 # only 100 more lines of code if you are lucky
 # and you have a lot more classes that look like this

end</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>How do you measure the design of your application?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='bonds bottom-left full-background slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>The interactions between classes (aka dependencies)</h1>
</div>
<div class='spacer bottom'></div>
<div class='attribution flickr'>
<a href='http://www.flickr.com/people/emsl/' target='_blank'>emsl</a>
</div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><img src="images/designPrinciples.png" alt="Principles of Design" /></p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>SOLID</h1>
<ul>
<li>Single Responsibility Principle</li>
<li>Open/Closed Principle</li>
<li>Liskov Substitution Principle</li>
<li>Interface Segregation Principle</li>
<li>Dependency Inversion Principle</li>
</ul>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Single Responsibiliy Principle</h1>
<h3>A class should have one, and only one, reason to change.</h3>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><textarea class='code' display='none' mode='ruby'>class FileProcessor
 
 def process_file(url)
 file = download_file(url)
 status = parse_file(file)
 report_status(status)
 end

 private 
 def download_file(url)
 # do some downloading stuff
 end

 def parse_file(file)
 # do that parsing stuff you do
 end

 def report_status(status)
 # probably email for now
 end

end</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>AND/OR</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Dependency Inversion Principle</h1>
<h3>Depend on abstractions, not on concretions.</h3>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><textarea class='code' display='none' mode='ruby'>class FileProcessor
 
 def process_file(url)
 file = download_file(url)
 status = parse_file(file)
 report_status(status)
 end

 private 
 def download_file(url)
 # do some downloading stuff
 end

 def parse_file(file)
 # do that parsing stuff you do
 end

 def report_status(status)
 # probably email for now
 end

end

processor.process_file(ftp://foo.com/my_file.pdf)</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><textarea class='code' display='none' mode='ruby '>class FileProcessor
 def initialize(reporter)
 @downloader = downloader
 @reporter = reporter
 end

 def process_file(url)
 downloader = Downloaders.find(url)
 file = downloder.get
 parser = Parsers.find(file)
 status = parser.parse
 @reporter.report(status)
 end

end

class Downloaders

 class FtpDownloader
 def get
 end
 end

 def self.find(url)
 end

end

class Parsers

 class PdfParser
 def initialize(file) 
 @file = file
 end
 def parse
 end
 end

 def self.find(file)
 return newPdfParser(file)
 end

end

class EmailReporter
 def report(status)
 end
end

processor = FileProcessor(new EmailReporter)
processor.process_file(ftp://foo.com/my_file.pdf)</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>What happens when you need to parse a CSV file?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><textarea class='code' display='none' mode='ruby '>class FileProcessor
 def initialize(reporter)
 @downloader = downloader
 @reporter = reporter
 end

 def process_file(url)
 downloader = Downloaders.find(url)
 file = downloder.get
 parser = Parsers.find(file)
 status = parser.parse
 @reporter.report(status)
 end

end

class Parsers

 class PdfParser
 def parse
 end
 end

 class CsvParser
 def parse
 end
 end

 def self.find(file)
 if file.extension == 'pdf'
 return new PdfParser(file)
 else
 return new CsvParser(file)
 end
 end

end

processor = FileProcessor(new EmailReporter)
processor.process_file(ftp://foo.com/my_file.csv)</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>What happens when you need to report via SMS?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><textarea class='code' display='none' mode='ruby '>class FileProcessor
 def initialize(reporter)
 @downloader = downloader
 @reporter = reporter
 end

 def process_file(url)
 downloader = Downloaders.find(url)
 file = downloder.get
 parser = Parsers.find(file)
 status = parser.parse
 @reporter.report(status)
 end

end

class SmsReporter
 def report(status)
 end
end

processor = FileProcessor(new SmsReporter)
processor.process_file(ftp://foo.com/my_file.pdf)</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Open/Closed Principle</h1>
<h3>You should be able to extend a classes behavior, without modifying it.</h3>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><img src="images/open-closed.png" alt="Dependency Graph" /></p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p>cool_library.rb</p>
<p><textarea class='code' display='none' mode='ruby'>class CoolLibrary

 def do_something_cool
 puts "I am cool!"
 end

 # and other cool things
end</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Fork it?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p>your_app.rb</p>
<p><textarea class='code' display='none' mode='ruby'>class CoolLibrary

 def do_something_cool
 puts "I am cool!"
 puts "I am more cool!"
 end

end

cool_library = new CoolLibrary

cool_library.do_something_cool

# no easy way to get back to original functionality</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p>your_app.rb</p>
<p><textarea class='code' display='none' mode='ruby'>class MyCoolLibrary < CoolLibrary

 def do_something_cool
 super
 puts "I am more cool!"
 end

end

cool_library = new MyCoolLibrary

cool_library.do_something_cool</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p>your_app.rb</p>
<p><textarea class='code' display='none' mode='ruby'>class CoolLibraryDecorator

 def initialize(cool_library)
 @cool_library = cool_library
 end

 def do_something_cool
 @cool_library.do_something_cool
 puts "I am more cool!"
 end

end

cool_library = newCoolLibraryDecorator(new CoolLibrary)

cool_library.do_something_cool</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Liskov Substitution Principle</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p>If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T. - Barbara Liskov</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><textarea class='code' display='none' mode='ruby'>class NormalMath

 def sq_root(number)
 # do some math on number
 # return some value to 4 decimal places
 end

end</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><textarea class='code' display='none' mode='ruby'>class PreciceMath

 def sq_root(number)
 # do some math on number
 # return some value to 8 decimal places
 end

end</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<p><textarea class='code' display='none' mode='ruby'>class SloppyMath

 def sq_root(number)
 # do some math on number
 # return some value to 2 decimal places
 end

end</textarea>
</p>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Can I freely substitute instances of these classes?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Ask for no more and promise no less.</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Interface Segregation Principle</h1>
<h3>Make fine grained interfaces that are client specific.</h3>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>But Ruby doesn't have interfaces?</h1>
</div>
<div class='spacer bottom'></div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>What about making your classes small and single responsibility?</h1>
<h2>Makes it easier for people to learn your API.</h2>
</div>
<div class='spacer bottom'></div>
</section>
<section class='bottom-left full-background mileage slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Your mileage may vary</h1>
</div>
<div class='spacer bottom'></div>
<div class='attribution flickr'>
<a href='http://www.flickr.com/people/kennejima/' target='_blank'>kennejima</a>
</div>
</section>
<section class='bottom-left full-background slide thankYou'>
<div class='spacer top'></div>
<div class='content'>
<h1>Thank you. Any questions?</h1>
</div>
<div class='spacer bottom'></div>
<div class='attribution flickr'>
<a href='http://www.flickr.com/people/27282406@N03/' target='_blank'>27282406@N03</a>
</div>
</section>
<section class='slide'>
<div class='spacer top'></div>
<div class='content'>
<h1>Resources</h1>
<ul>
<li><a href="http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf">http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf</a></li>
<li><a href="http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod">http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod</a></li>
<li><a href="http://confreaks.com/videos/240-goruco2009-solid-object-oriented-design">http://confreaks.com/videos/240-goruco2009-solid-object-oriented-design</a></li>
<li><a href="http://confreaks.com/videos/185-rubyconf2009-solid-ruby">http://confreaks.com/videos/185-rubyconf2009-solid-ruby</a></li>
<li><a href="http://blog.rubybestpractices.com/posts/gregory/055-issue-23-solid-design.html">http://blog.rubybestpractices.com/posts/gregory/055-issue-23-solid-design.html</a></li>
<li><a href="http://mmiika.wordpress.com/oo-design-principles/">http://mmiika.wordpress.com/oo-design-principles/</a></li>
</ul>
</div>
<div class='spacer bottom'></div>
</section>
<!-- deck.js navigation extension -->
<a class='deck-prev-link' href='#' title='Previous'>←</a>
<a class='deck-next-link' href='#' title='Next'>→</a>
<!-- deck.js hash extension -->
<a class='deck-permalink' href='.' title='Permalink to this slide'>#</a>
<!-- deck.js status extension -->
<p class='deck-status'>
<span class='deck-status-current'></span>
/
<span class='deck-status-total'></span>
</p>
<!-- jQuery & deck.js -->
<script src="deck.js/support/jquery.1.6.4.min.js" type="text/javascript"></script>
<script src="deck.js/core/deck.core.js" type="text/javascript"></script>
<!-- deck.js extension JS files -->
<script src="deck.js/extensions/codemirror/codemirror.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/deck.codemirror.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/clike/clike.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/clojure/clojure.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/coffeescript/coffeescript.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/css/css.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/diff/diff.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/haskell/haskell.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/htmlmixed/htmlmixed.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/javascript/javascript.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/lua/lua.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/php/php.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/plsql/plsql.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/python/python.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/r/r.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/rst/rst.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/ruby/ruby.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/scheme/scheme.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/smalltalk/smalltalk.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/sparql/sparql.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/stex/stex.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/velocity/velocity.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/xml/xml.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/xmlpure/xmlpure.js" type="text/javascript"></script>
<script src="deck.js/extensions/codemirror/mode/yaml/yaml.js" type="text/javascript"></script>
<script src="deck.js/extensions/goto/deck.goto.js" type="text/javascript"></script>
<script src="deck.js/extensions/hash/deck.hash.js" type="text/javascript"></script>
<script src="deck.js/extensions/menu/deck.menu.js" type="text/javascript"></script>
<script src="deck.js/extensions/navigation/deck.navigation.js" type="text/javascript"></script>
<script src="deck.js/extensions/scale/deck.scale.js" type="text/javascript"></script>
<script src="deck.js/extensions/status/deck.status.js" type="text/javascript"></script>
<!-- your custom JS here, including call to initialize deck.js-codemirror -->
<script src="js/better_ruby_mtn_west.js" type="text/javascript"></script>
<!-- Initialize the deck. -->
<script type='text/javascript'>
$(function() { $.deck('.slide'); });
</script>
</body>
</html>