-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupplier.py
More file actions
111 lines (94 loc) · 2.53 KB
/
supplier.py
File metadata and controls
111 lines (94 loc) · 2.53 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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Date : 2020/8/6
# @Author : Bruce Liu /Lin Luo
# @Mail : 15869300264@163.com
from abc import ABCMeta, abstractmethod
from creational.example.component import MotherBoard, CpuHigh, CpuLow, MemoryHigh, MemoryLow, \
StorageHigh, StorageLow, MotherBoardLow, MotherBoardHigh
class SupplierBuilder(metaclass=ABCMeta):
"""
主板供应商基类
这是个生成器方法
"""
def __init__(self):
self._mother_board = None
@abstractmethod
def add_cpu(self) -> None:
"""
添加cpu
:return:
"""
pass
@abstractmethod
def add_memory(self) -> None:
"""
添加内存
:return:
"""
pass
@abstractmethod
def add_storage(self) -> None:
"""
添加闪存
:return:
"""
pass
def get_mother_board(self) -> MotherBoard:
"""
返回制造完毕的主板
:return:
"""
return self._mother_board
class SupplierAlpha(SupplierBuilder):
"""
Alpha供应商,主要提供高端主板
"""
def __init__(self):
"""
继承主板生成器类
同时添加新属性_mother_board
"""
super(SupplierAlpha, self).__init__()
self._mother_board = MotherBoardHigh()
def add_cpu(self) -> None:
"""
实例化具体的cpu,并添加到主板上
:return:
"""
cpu = CpuHigh()
self._mother_board.cpu = cpu
def add_memory(self) -> None:
"""
实例化具体的内存,并添加到主板上
:return:
"""
memory = MemoryHigh()
self._mother_board.memory = memory
def add_storage(self) -> None:
"""
实例化具体的闪存,并添加到主板上
:return:
"""
storage = StorageHigh()
self._mother_board.storage = storage
class SupplierBeta(SupplierBuilder):
"""
beta供应商,主要提供低端主板
"""
def __init__(self):
"""
继承主板生成器类
同时添加新属性_mother_board
"""
super(SupplierBeta, self).__init__()
self._mother_board = MotherBoardLow()
def add_cpu(self) -> None:
cpu = CpuLow()
self._mother_board.cpu = cpu
def add_memory(self) -> None:
memory = MemoryLow()
self._mother_board.memory = memory
def add_storage(self) -> None:
storage = StorageLow()
self._mother_board.storage = storage