Python/Python__DesignPattern

adapter pattern

말하는감자 2020. 12. 1. 17:10

 

class

class Chiwawa:

    def __init__(self):
	self.__dog_name = "wawa"
    
    @property
    def dog_name(self):
        return self.__dog_name

    @dog_name.setter
    def dog_name(self, value):
        self.__dog_name = value

    def print_name(self):
        print(self.__dog_name)
class Poodle:

    def __init__(self):
	self.__dog_name = "zzong"
    
    @property
    def dog_name(self):
        return self.__dog_name

    @dog_name.setter
    def dog_name(self, value):
        self.__dog_name = value

    def print_name(self):
        print(self.__dog_name)

 

adapter

class DogAdapter:
    def __init__(self, chiwawa, poodle):
        self.chiwawa = chiwawa
        self.poodle = poodle

    def print_dog(self):
        self.chiwawa.print_name()
        self.poodle.print_name()

 

main

if __name__ == '__main__':
    chiwawa = Chiwawa()
    poodle = Poodle()

    adapter = DogAdapter(chiwawa, poodle)

    adapter.print_dog()

'Python > Python__DesignPattern' 카테고리의 다른 글

adapter pattern  (0) 2020.12.01
facade pattern  (0) 2020.12.01
singleton pattern  (0) 2020.12.01