|
| 1 | +from abc import abstractmethod |
| 2 | + |
| 3 | + |
| 4 | +class Store(): |
| 5 | + def __init__(self): |
| 6 | + self.full_dict = {} |
| 7 | + |
| 8 | + def get_unit(self, unit, name): |
| 9 | + unit.set_id(name) |
| 10 | + self.full_dict[name] = unit |
| 11 | + |
| 12 | + |
| 13 | + def move_to_office(self, id): |
| 14 | + get_unit = self.full_dict.get(id) |
| 15 | + if get_unit: |
| 16 | + res = self.full_dict.pop(id) |
| 17 | + print(f'{res} move to office') |
| 18 | + return res |
| 19 | + else: |
| 20 | + print(f'NOT in store {id}') |
| 21 | + return None |
| 22 | + |
| 23 | + |
| 24 | + def check_store(self): |
| 25 | + print(f'all in store {len(self.full_dict)} units') |
| 26 | + if len(self.full_dict): |
| 27 | + print(f'this units is:') |
| 28 | + for name, cls in self.full_dict.items(): |
| 29 | + print(name, cls) |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +class Office_equipment(): |
| 34 | + @abstractmethod |
| 35 | + def __init__(self, in_name, in_type): |
| 36 | + self.name = in_name |
| 37 | + self.type_is = in_type |
| 38 | + |
| 39 | + def __str__(self): |
| 40 | + return f'{self.name} {self.type_is}' |
| 41 | + |
| 42 | + def to_print(self): |
| 43 | + print('need define') |
| 44 | + |
| 45 | + def get_name(self): |
| 46 | + print(f'{self.name} - {self.type_is}') |
| 47 | + |
| 48 | + |
| 49 | +class Printer(Office_equipment): |
| 50 | + def __init__(self, name, type_is): |
| 51 | + super().__init__(name, type_is) |
| 52 | + |
| 53 | + @abstractmethod |
| 54 | + def to_do(self): |
| 55 | + print(f'{self.name} print pages') |
| 56 | + |
| 57 | + def __str__(self): |
| 58 | + return f'{self.name} {self.type_is}' |
| 59 | + |
| 60 | + |
| 61 | +class Scaner(Office_equipment): |
| 62 | + def __init__(self, name, type_is): |
| 63 | + super().__init__(name, type_is) |
| 64 | + |
| 65 | + def to_scan(self): |
| 66 | + print(f'{self.name} scan to pages') |
| 67 | + |
| 68 | + |
| 69 | +class MFU(Scaner, Printer): |
| 70 | + def __init__(self, name, type_is): |
| 71 | + Scaner.__init__(self, name, type_is) |
| 72 | + Printer.__init__(self, name, type_is) |
| 73 | + # self.id = prop |
| 74 | + |
| 75 | + def to_do(self): |
| 76 | + Scaner.to_scan(self) |
| 77 | + Printer.to_print(self) |
| 78 | + |
| 79 | + def get_inheritance(self): |
| 80 | + print(f'full inheritance clases:\n {MFU.__mro__}') |
| 81 | + |
| 82 | + @classmethod |
| 83 | + def get_info_class(cls): |
| 84 | + print(cls) |
| 85 | + |
| 86 | + @abstractmethod |
| 87 | + def check_info_mfu(cls): |
| 88 | + print(cls.__mro__) |
| 89 | + print(cls.__module__) |
| 90 | + print(cls.__dict__) |
| 91 | + |
| 92 | + @property |
| 93 | + def get_id(self): |
| 94 | + print(f'{self.name} have id {self.id}') |
| 95 | + |
| 96 | + def set_id(self, in_id): |
| 97 | + self.id = in_id |
| 98 | + |
| 99 | + |
| 100 | +st = Store() # создаем склад |
| 101 | +st.check_store() # проверяем склад |
| 102 | + |
| 103 | +mfu = MFU('Xerox', 'R320') # у нас есть МФУ |
| 104 | +MFU.get_info_class() # проверяем класс |
| 105 | +MFU.check_info_mfu(MFU) # наследование, название модуля, информация о классе |
| 106 | + |
| 107 | +st.get_unit(mfu, '1555') # добавляем мфу на склад присваивая id идентификационный номер |
| 108 | +st.check_store() |
| 109 | + |
| 110 | +mfu = st.move_to_office('1555') # склад передает МФУ в офис |
| 111 | + |
| 112 | +mfu.to_do() # тестируем МФУ это принтер и сканер одновременно |
| 113 | +mfu.get_name() |
| 114 | +mfu.to_scan() # проверяем только сканирование |
| 115 | +mfu.get_inheritance() # проверяем наследование |
| 116 | +print(mfu.get_id) # проверяем id |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +mfu = st.move_to_office('1555') # пытаемся получить со склада такой-же МФУ |
0 commit comments