Created
September 5, 2011 10:28
-
-
Save bblimke/1194652 to your computer and use it in GitHub Desktop.
DCI and Inheritance
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 Vehicle | |
attr_reader: speed | |
end | |
class Ship < Vehicle | |
attr_accessor: anchor | |
end | |
class Airplane < Vehicle | |
attr_accessor :wings | |
end | |
module Motorized | |
def start_engines | |
#start engine logic | |
end | |
end | |
module Flyable | |
def take_off | |
#take off logic | |
end | |
end | |
module Sailable | |
def sail | |
#sail logic | |
end | |
end | |
plane = Airplane.new | |
ship = Ship.new | |
def RunwayContext | |
plane.mixin Motorized | |
plane.mixin Flyable | |
plane.start_engines | |
plane.take_off | |
end | |
def WaterContext | |
ship.mixin Motorized | |
ship.mixin Sailable | |
ship.start_engines | |
ship.sail | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment