Last active
November 25, 2017 05:22
-
-
Save Sihui/8c5dfda991296b8dd8b3ac303e3dccfa to your computer and use it in GitHub Desktop.
Design Pattern: Observer and Podcasts
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 Podcast | |
attr_reader :episodes, :subscribers | |
def initialize() | |
@episodes = [] | |
@subscribers = [] | |
end | |
def add_subscriber(new_subscriber) | |
subscribers << new_subscriber | |
end | |
def remove_subscriber(party_pooper) | |
subscribers.delete(party_pooper) | |
end | |
def add_episode(new_episode) | |
episodes << new_episode | |
subscribers.each do |subscriber| | |
subscriber.update(self) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment