RubyでTemplateパターン
TemplateパターンはJavaと同じ感覚で書けますね。
class BaseAction def execute() doValidate(); doExecute() end end class AddAction<BaseAction def doValidate() puts "AddAction.doValidate()" end def doExecute() puts "AddAction.doExecute()" end end class DeleteAction<BaseAction def doValidate() puts "DeleteAction.doValidate()" end def doExecute() puts "DeleteAction.doExecute()" end end # create add = AddAction.new delete = DeleteAction.new # execute add.execute delete.execute
実行結果
AddAction.doValidate() AddAction.doExecute() DeleteAction.doValidate() DeleteAction.doExecute()