Created
January 18, 2012 21:49
-
-
Save anewusername1/1635981 to your computer and use it in GitHub Desktop.
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
class Car < CarElement | |
def initialize | |
# Here we build an array of objects that will be visited. This can be done | |
# after initialize as well; it just needs to be built before calling 'accept'. | |
@elements = [] | |
@elements << Wheel.new("front left") | |
@elements << Wheel.new("front right") | |
@elements << Wheel.new("back left") | |
@elements << Wheel.new("back right") | |
@elements << Body.new | |
@elements << Engine.new | |
end | |
# go through each element and 'visit' it | |
def accept(visitor) | |
@elements.each do |element| | |
element.accept(visitor) | |
end | |
visitor.visit(self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment