class Bulb
def turnOn
puts "電気がつきました"
end
def turnOff
puts "真っ暗です"
end
end
class Command
def execute
end
def undo
end
def redo
end
end
class TurnOn < Command
def initialize(bulb)
@bulb = bulb
end
def execute
@bulb.turnOn
end
def undo
@bulb.turnOff
end
def redo
execute
end
end
class TrunOff < Command
def initialize(bulb)
@bulb = bulb
end
def execute
@bulb.turnOff
end
def undo
@bulb.turnOn
end
def redo
execute
end
end
class RemoteControll
def submit(command)
@command = command.execute
end
end
bulb = Bulb.new
turnOn = TurnOn.new(bulb)
turnOff = TrunOff.new(bulb)
remote_controll = RemoteControll.new
remote_controll.submit(turnOn)
remote_controll.submit(turnOff)