Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from abc import ABC, abstractmethod
- # abstract creator
- class CreateData(ABC):
- @abstractmethod
- def data(self):
- pass
- def added_data(self):
- result = self.data()
- return result.add_items()
- # concrete creator (Haters)
- class CreateHatersManual(CreateData):
- def data(self):
- return ManualHaters()
- # concrete creator (Hated)
- class CreateHatedManual(CreateData):
- def data(self):
- return ManualHated()
- # abstract product
- class Data(ABC):
- @abstractmethod
- def add_items(self):
- pass
- # concrete product (Haters)
- class ManualHaters(Data):
- def __init__(self):
- print(f"let's input names of haters and after - persons, hated by haters!")
- def add_hated(self):
- print('please, input names. if you have enough, press q\n')
- inputdata = []
- while True:
- b = input('one of the names\n')
- if b == 'q':
- break
- else:
- inputdata.append(b)
- return inputdata
- def add_items(self):
- inputdata = dict.fromkeys(self.add_hated(), {})
- for name in inputdata.keys():
- print(f"items, covered by {name}")
- inputdata[name] = set(self.add_hated())
- return inputdata
- # concrete product (Hated)
- class ManualHated(Data):
- def __init__(self):
- print(f"let's input names of hated persons!")
- def add_items(self):
- print('please, input names. if you have enough, press q\n')
- inputdata = []
- while True:
- b = input('one of the names\n')
- if b == 'q':
- break
- else:
- inputdata.append(b)
- return set(inputdata)
- def get_data(creator):
- result = creator.added_data()
- return result
- if __name__ == "__main__":
- hated = get_data(CreateHatedManual())
- haters = get_data(CreateHatersManual())
- print(haters)
- print(hated)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement