An Easier Way of Command Pattern : Command « Design Patterns « Ruby






An Easier Way of Command Pattern


class Commander
  attr_accessor :command

  def initialize(command)
    @command = command
  end

  def on_button_push
    @command.execute if @command
  end
end

class YourCommand
  def execute
  end
end

save_button = Commander.new( YourCommand.new )

 








Related examples in the same category

1.Code Blocks as Commands
2.Commands That Record (Command and composite pattern)
3.Undo by a Command