-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent.py
More file actions
367 lines (279 loc) · 7.29 KB
/
component.py
File metadata and controls
367 lines (279 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Date : 2020/8/6
# @Author : Bruce Liu /Lin Luo
# @Mail : 15869300264@163.com
from abc import abstractmethod
from copy import deepcopy
class Component(object):
"""
基础组建类
包括了三个属性,名称、版本和信息
"""
def __init__(self):
self._name = None
self._version = None
self._info = None
@property
def name(self) -> str:
return self._name
@name.setter
def name(self, name: str) -> None:
self._name = name
@property
def version(self) -> str:
return self._version
@version.setter
def version(self, version: str) -> None:
self._version = version
@property
def info(self) -> str:
return self._info
@info.setter
def info(self, info: str) -> None:
self._info = info
class Prototype(object):
"""
原型基类,提供了clone函数
"""
@abstractmethod
def clone(self):
pass
class Os(Component, Prototype):
"""
操作系统基类,继承了基础组建类和原型基类
"""
def __init__(self):
super(Os, self).__init__()
self._name = 'android'
self._version = '4.0'
self._info = 'android operation system ver 4.0'
def clone(self):
"""
实现克隆方法,返回克隆的操作系统对象
这里偷懒使用了python自带的deepcopy函数,也可以自行实例化一个Os类,然后将属性赋给新实例化的对象
:return:
"""
return deepcopy(self)
class OsPre(Os):
"""
老版操作系统
"""
def __init__(self):
super(OsPre, self).__init__()
class OsNew(Os):
"""
新版操作系统,
在初始化时,修改了版本号和信息的内容
"""
def __init__(self):
super(OsNew, self).__init__()
self._version = '6.0'
self._info = 'android operation system ver 6.0'
class Cpu(Component):
"""
cpu基类,继承了基础组建类
"""
pass
class CpuLow(Cpu):
"""
低端cpu类
"""
def __init__(self):
super(CpuLow, self).__init__()
self._name = 'KR'
self._version = '3000'
self._info = 'cpu KR 3000'
class CpuHigh(Cpu):
"""
高端cpu类
"""
def __init__(self):
super(CpuHigh, self).__init__()
self._name = 'QT'
self._version = '600'
self._info = 'cpu QT 600'
class Memory(Component):
"""
内存基类,继承了基础组建类
"""
pass
class MemoryLow(Memory):
"""
低端内存类
"""
def __init__(self):
super(MemoryLow, self).__init__()
self._name = 'KTS 1'
self._version = 'DDR3'
self._info = 'KST 1 DDR3 2G'
class MemoryHigh(Memory):
"""
高端内存类
"""
def __init__(self):
super(MemoryHigh, self).__init__()
self._name = 'KTS 2'
self._version = 'DDR4'
self._info = 'KST 2 DDR4 4G'
class Logo(Component, Prototype):
"""
logo基类,继承了基础组建类和原型基类
"""
def __init__(self):
"""
在基础组建类基础上增加了pic属性
"""
super(Logo, self).__init__()
self._pic = None
@property
def pic(self) -> str:
return self._pic
@pic.setter
def pic(self, pic: str) -> None:
self._pic = pic
def clone(self):
"""
实现clone方法
:return:
"""
return deepcopy(self)
class LogoAlpha(Logo):
"""
具体logo类,定义了pic属性的值
"""
def __init__(self):
super(LogoAlpha, self).__init__()
self._pic = 'alpha'
class LogoBeta(Logo):
"""
具体logo类,定义了pic属性的值
"""
def __init__(self):
super(LogoBeta, self).__init__()
self._pic = 'beta'
class Storage(Component):
"""
闪存基类,继承了基础组建类
"""
def __init__(self):
"""
在基础组建类的基础上添加了os属性,即在闪存中存储的os
"""
super(Storage, self).__init__()
self._os = None
@property
def os(self) -> Os:
return self._os
@os.setter
def os(self, os: Os) -> None:
self._os = os
class StorageLow(Storage):
"""
低端闪存类
"""
def __init__(self):
super(StorageLow, self).__init__()
self._name = 'SS 1'
self._version = 'eMMc'
self._info = 'SS 1 eMMc 64G'
class StorageHigh(Storage):
"""
高端闪存类
"""
def __init__(self):
super(StorageHigh, self).__init__()
self._name = 'SS 2'
self._version = 'UFS'
self._info = 'SS 2 UFS 64G'
class MotherBoard(Component):
"""
主板基类,继承了基础组建类
"""
def __init__(self):
"""
在基础组建类的基础上,增加了内存、cpu、闪存等属性
"""
super().__init__()
self._memory = None
self._cpu = None
self._storage = None
@property
def cpu(self) -> Cpu:
return self._cpu
@cpu.setter
def cpu(self, cpu: Cpu) -> None:
self._cpu = cpu
@property
def memory(self) -> Memory:
return self._memory
@memory.setter
def memory(self, memory: Memory) -> None:
self._memory = memory
@property
def storage(self) -> Storage:
return self._storage
@storage.setter
def storage(self, storage: Storage) -> None:
self._storage = storage
class MotherBoardLow(Component):
"""
低端主板类
"""
def __init__(self):
super(MotherBoardLow, self).__init__()
self._name = 'b350'
self._version = '1.0'
self._info = 'mother board b350'
class MotherBoardHigh(Component):
"""
高端主板类
"""
def __init__(self):
super(MotherBoardHigh, self).__init__()
self._name = 'h370'
self._version = '1.0'
self._info = 'mother board b370'
class Mould(Component):
"""
基础模具类,继承了基础组建类
"""
def __init__(self):
"""
在基础组建类的基础上,增加了logo和主板
"""
super(Mould, self).__init__()
self._mother_board = None
self._logo = None
@property
def mother_board(self) -> MotherBoard:
return self._mother_board
@mother_board.setter
def mother_board(self, mother_board):
self._mother_board = mother_board
@property
def logo(self) -> Logo:
return self._logo
@logo.setter
def logo(self, logo: Logo) -> None:
self._logo = logo
def information(self):
print(f'logo: {self.logo.pic}')
print(f'mother board: {self.mother_board.info}')
print(f'os: {self.mother_board.storage.os.info}')
print(f'cpu: {self.mother_board.cpu.info}')
print(f'memory: {self.mother_board.memory.info}')
print(f'storage: {self.mother_board.storage.info}')
class Product(Component):
"""
产品类
"""
def __init__(self):
super(Product, self).__init__()
self._mould = None
@property
def mould(self) -> Mould:
return self._mould
@mould.setter
def mould(self, mould: Mould) -> None:
self._mould = mould