Skip to content

Instantly share code, notes, and snippets.

@PJK
Created March 11, 2015 16:33
Show Gist options
  • Save PJK/d788875dcb886de92cc2 to your computer and use it in GitHub Desktop.
Save PJK/d788875dcb886de92cc2 to your computer and use it in GitHub Desktop.
Bridge pattern
class Window
def initialize
# Implementor selection strategy
extend [WindowsAPI, X11API].sample
end
def drawRectangle
4.times { drawLine }
end
end
class TitledWindow < Window
def drawTitle
drawText 'This is my title'
end
end
class BorderWindow < Window
def drawBorder
drawRectangle
drawText 'Border window description'
end
end
module WindowsAPI
def drawLine
puts 'This is a Windows line'
end
def drawText(text)
puts "Windows text: #{text}"
end
end
module X11API
def drawLine
puts 'This is an X11 line'
end
def drawText(text)
puts "X11 text: #{text}"
end
end
TitledWindow.new.drawTitle
puts
BorderWindow.new.drawBorder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment