방문자 패턴

김대익·2022년 4월 4일
0

class Visitor:
  def visit(self,elem):
    pass

class NameVisitor(Visitor):
  def visit(self,elem):
    print(elem.name)

class AgeVisitor(Visitor):
  def visit(self,elem):
    print(elem.age)


class Cat:
  def __init__(self,name,age):
    self.name = name
    self.age = age

  def speak(self):
    print("meow")

  def accept(self,visitor:Visitor):
    print("use implementation of visitor")
    visitor.visit(self)

0개의 댓글