Last active
August 29, 2015 14:10
-
-
Save stevecass/9b555430e2bddb2004e5 to your computer and use it in GitHub Desktop.
Composition and delegation
This file contains 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
# WheelType knows about the behavior of wheels | |
class WheelType | |
def diameter | |
#snip | |
end | |
def rim_size | |
#snip | |
end | |
def weight | |
#snip | |
end | |
end | |
class Bicycle | |
attr_accessor :wheel_type | |
def initialize options = {} | |
#do some stuff | |
self.wheel_type = WheelType.new options | |
end | |
def rim_size | |
#delegate to wheel_type | |
wheel_type.rim_size | |
end | |
# add other delegate methods for | |
# wheel weight diameter, behavior | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment