通俗说就是,A代理B做了一些B不方便露面的事情,见不得人的勾当。
from abc import abstractmethod, ABC
'''送礼物抽象接口类'''
class GiveGift(ABC):
@abstractmethod
def give_dolls(self):
pass
@abstractmethod
def give_flowers(self):
pass
@abstractmethod
def give_chocolate(self):
pass
@abstractmethod
def give_letters(self):
pass
'''追求者类'''
class Pursuit(GiveGift):
def __init__(self, mm):
self.mm = mm
def give_dolls(self):
print(self.mm + " 送你洋娃娃")
def give_flowers(self):
print(self.mm + " 送你鲜花")
def give_chocolate(self):
print(self.mm + " 送你巧克力")
def give_letters(self):
print(self.mm + " 送你情书")
'''代理类'''
class Proxy(GiveGift):
def __init__(self, pursuit):
self.gg = pursuit
def give_dolls(self):
self.gg.give_dolls()
def give_flowers(self):
self.gg.give_flowers()
def give_chocolate(self):
self.gg.give_chocolate()
def give_letters(self):
self.gg.give_letters()
if __name__ == '__main__':
pursuit = Pursuit('杨超越')
proxy = Proxy(pursuit)
proxy.give_dolls()
proxy.give_chocolate()
proxy.give_flowers()
proxy.give_letters()