Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Friend observer, Party publisher solution in Clear category for Party Invitations by kkkkk
class Friend:
"""Observer for Party Publisher, contains name and last party invite."""
def __init__(self, name):
self._name = name
self._location = None
self._party_time = None
def invited(self, location, party_time):
"""Receive and record invitation."""
self._location = location
self._party_time = party_time
def show_invite(self):
"""Show location and date of last invite."""
if not self._location:
return "No party..."
return f'{self._location}: {self._party_time}'
class Party:
"""Publisher of party invites."""
def __init__(self, location):
self._observers = set()
self._location = location
def add_friend(self, friend):
"""Add friend to list of people who will receive an invitation."""
if not isinstance(friend, Friend):
raise TypeError()
self._observers.add(friend)
def del_friend(self, friend):
"""Remove friend from list of people who will receive an invitation."""
self._observers.remove(friend)
def send_invites(self, party_time):
"""Send invite with day, time to each person on party list."""
for friend in self._observers:
friend.invited(self._location, party_time)
March 22, 2020