forked from foxli180/BeginningPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
personal-Factorymode.py
90 lines (66 loc) · 2 KB
/
personal-Factorymode.py
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
class Operation:
def __init__(self):
self.__NumberA = 0.0
self.__NumberB = 0.0
'''
def NumberA(self,value):
def __get__(self):
return self.__NumberA
def __set__(self,value):
self.__NumberA = value
#'''
def getNumberA(self):
return self.__NumberA
def setNumberA(self,value):
self.__NumberA = value
NumberA = property(getNumberA,setNumberA)
def NumberB(self,value):
def __get__(self):
return self.__NumberB
def __set__(self,value):
self.__NumberB= value
def getResult(self):
result = 0.0
return result
class OperationAdd(Operation):
def getResult (self):
result = 0.0
result = self.NumberA + self.NumberB
return result
class OperationSub(Operation):
def getResult(self):
result = 0.0
result = self.NumberA - self.NumberB
return result
class OperationMul(Operation):
def getResult(self):
result = 0.0
result = self.NumberA * self.NumberB
return result
class OperationDiv(Operation):
def getResult(self):
result = 0.0
try:
result = self.NumberA/self.NumberB
except ZeroDivisionError:
print ("Check NumberB:"+" divison by zero")
class OperationFactory:
@staticmethod
def CreateOperrator(operator):
oper = Operation ()
oper = {
'+' : lambda : OperationAdd(),
'-' : lambda : OperationSub(),
'*' : lambda : OperationMul(),
'/' : lambda : OperationDiv()
}[operator]()
return oper
def test():
#oper = Operation()
oper = OperationFactory.CreateOperrator('*')
print (oper.NumberA)
oper.NumberA = 20
oper.NumberB = 30
print (oper.NumberA)
print (oper.getResult())
if __name__ =='__main__':test()