1. Looks like you cared
2. Pretty much what you expected
3. Language looks as perfect fit
for problem
My definition
Slide 6
Slide 6 text
Design Patterns
circular friction
reduction device
with central axis
=
Slide 7
Slide 7 text
bad code
class Report
def initialize
@title = 'Monthly Report'
@text = [ 'Things are going', 'really, really well.' ]
end
def output_report
...HTML specific stuff...
end
end
template method: reports
Slide 8
Slide 8 text
template method: reports better code
class Report
def initialize
@title = 'Monthly Report'
@text = ['Things are going', 'really, really
well.']
end
def output_report
output_start
output_head
@text.each do |line|
output_line(line)
end
output_end
end
def output_start; end
def output_head
output_line(@title)
end
def output_line(line)
raise 'Called abstract method: output_line'
end
def output_end; end
end
Slide 9
Slide 9 text
Design Principles
THE THEORY BEHIND THE THEORY
Slide 10
Slide 10 text
S
O
L
I
D
ingle responsibility
pen closed
iskov substitution
nterface segragation
ependency inversion
Uncle
Bob Martin
Can’t tell what it
does at a glance, it’s
TOO LONG
More than one level of
nesting, probably
TOO LONG
TOO LONG
More than one level of
abstraction, may be
Flog score greater
than 15, may be
TOO LONG
REFACTOR
Slide 15
Slide 15 text
Extract Method:
Split method into many
auxiliary methods
Solution #1
Slide 16
Slide 16 text
Replace temp with query:
Move local variables
into methods
Solution #2
Slide 17
Slide 17 text
large class
Smell number 2
Slide 18
Slide 18 text
Need to scroll to know
what it does, it’s
TOO BIG
More private methods
than public, it’s
TOO BIG
TOO BIG
More than seven
methods, probably
Flog score greater
than 50, may be
TOO BIG
REFACTOR
Slide 19
Slide 19 text
Extract class:
If the class has multiple
responsibilities
Solution #1
Slide 20
Slide 20 text
Extract service object:
If the class has many
objects related to a
single action
Solution #2