-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract.py
More file actions
71 lines (66 loc) · 2.37 KB
/
contract.py
File metadata and controls
71 lines (66 loc) · 2.37 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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Date : 2020/8/10
# @Author : Bruce Liu /Lin Luo
# @Mail : 15869300264@163.com
from creational.example.component import Os, Logo, Mould, MotherBoard, MotherBoardHigh
from creational.example.pipeline import Pipeline
from creational.example.supplier import SupplierBuilder, SupplierAlpha, SupplierBeta
class Contract(object):
def __init__(self, first_part: str, second_part: str, num: int, mother_board: MotherBoard.__subclasses__(),
os: Os.__subclasses__(), logo: Logo.__subclasses__(), mould: Mould.__class__):
"""
合同模版
同时带有试制和量产的操作
某种意义上,合同类也是个工厂方法
:param first_part: 甲方
:param second_part: 乙方
:param num: 订单数量
:param mother_board: 主板
:param os: 操作系统
:param logo: logo
:param mould: 模具厂
"""
self._first_part = first_part
self._second_part = second_part
self._num = num
self._supplier = self._mother_board_supplier(mother_board)
self._os = os
self._logo = logo
self._mould = mould
self._pipeline = Pipeline()
@staticmethod
def _mother_board_supplier(mother_board: MotherBoard.__subclasses__()) -> SupplierBuilder.__subclasses__():
"""
主板供应商选择
:param mother_board: 主板型号
:return:
"""
# 根据主板型号,获取供应商
# 这里有更优雅的写法,大家可以去修改优化
if issubclass(mother_board, MotherBoardHigh):
# 高端主板供应商
return SupplierAlpha
else:
# 低端主板供应商
return SupplierBeta
def trial_produce(self):
"""
试制
显示手机制造的整个过程及信息
:return:
"""
print('begin to trial produce')
phone = self._pipeline.produce_phone(supplier=self._supplier, os=self._os, logo=self._logo,
mould=self._mould)
print('trial produce complete')
return phone
def produce(self):
"""
量产
这里不进行具体展示
:return:
"""
print('begin to produce')
pass
print(f'{self._num} products produced completed')