observer pattern

김대익·2022년 4월 4일
0


class Observer:
  def update(self):
    pass

class Cat(Observer):
  def update(self):
    print('meow')

class Dog(Observer):
  def update(self):
    print('bark')

class Owner:
  def __init__(self):
    self.animals = []
  def register(self,animal:Observer):
    self.animals.append(animal)
  
  def notify(self):
    for animal in self.animals:
      animal.update()

0개의 댓글