Created
March 11, 2015 16:33
-
-
Save PJK/d788875dcb886de92cc2 to your computer and use it in GitHub Desktop.
Bridge pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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