Skip to content

Instantly share code, notes, and snippets.

@Sihui
Created July 28, 2017 04:48
Show Gist options
  • Save Sihui/cffd31dc9569bc99914e9c1022ca40ab to your computer and use it in GitHub Desktop.
Save Sihui/cffd31dc9569bc99914e9c1022ca40ab to your computer and use it in GitHub Desktop.
Design Pattern: Command and Hotel Service
class ServicePanel
attr_reader :button_a1, :button_a2, :button_b1, :button_b2
def initialize(a1_service, a2_service,
b1_service, b2_service)
@button_a1 = Button.new(a1_service)
@button_a2 = Button.new(a2_service)
@button_b1 = Button.new(b1_service)
@button_b2 = Button.new(b2_service)
end
end
class Button
attr_reader :service
def initialize(service)
@service = service
end
def on_button_click
service.execute
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment