7. デザインパターンの分類
• デザインパターンは設計上のパターン
– GoFのデザインパターン(23パターン)
GoF(Gang of Four)と呼ばれる四人がカタログ化
: Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides
– J2EEパターン(15パターン)
Sun Java Centerで、J2EEに有用なものをカタログ化
– 分散・並行化設計パターン
Pattern Languages of Programsワークショップ選出のものなど
デザインパターン
GoFの
デザインパターン
J2EEパターン
分散・並行化
設計パターン
17. コード(役職)
class
Yakushoku
def
ask
puts
"
"
end
end
class
Tanto
<
Yakushoku
def
ask
puts
"まずは様子を見ましょう"
end
end
class
Shunin
<
Yakushoku
def
ask
puts
"積極的に攻めていきましょう"
end
end
18. コード(社員)
class
Shain
def
iniBalize
@yakushoku
=
Yakushoku.new
end
def
ask
@yakushoku.ask
end
def
set_yakushoku_tanto
@yakushoku
=
Tanto.new
end
def
set_yakushoku_shunin
@yakushoku
=
Shunin.new
end
end
28. コード 組織単位
class Unit
attr_accessor :name, :contacts
def initialize(name, contacts)
@name, @contacts = name, contacts
end
def work
puts `働きます!`
end
end
unit.rb
30. コード 部⾨門
require_relative 'unit'
class Bumon < Unit
attr_accessor :units
def initialize(name, contacts)
super
@units = []
end
def add(unit)
units << unit
end
bumon.rb
31. コード 部⾨門(続き)
def work
puts name + " : チームワークを発揮します。"
end
def work_all
@units.each {|unit| unit.work}
end
def get_child
return units[0]
end
end
差し当たって、1つ返しておく!!