Created
November 2, 2010 11:21
-
-
Save cheeyeo/659497 to your computer and use it in GitHub Desktop.
Composition over 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 Engine | |
def initialize | |
# set engine properties here etc | |
end | |
# other engine methods | |
end | |
class Car < Vehicle | |
def initialize | |
@engine = Engine.new | |
end | |
def sunday_drive | |
start_engine | |
stop_engine | |
end | |
def start_engine | |
@engine.start | |
end | |
def stop_engine | |
@engine.stop | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment