Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created November 2, 2010 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cheeyeo/659497 to your computer and use it in GitHub Desktop.
Save cheeyeo/659497 to your computer and use it in GitHub Desktop.
Composition over inheritance
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