Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- class MathOperator(object):
- def __init__(self, name):
- self.result = 0
- print(name)
- def work(self, a, b): pass
- def get(self): return self.result
- class OperationSum(MathOperator):
- def __init__(self): super(OperationSum, self).__init__('OperationSum')
- def work(self, a, b): self.result = a + b
- class OperationMult(MathOperator):
- def __init__(self): super(OperationMult, self).__init__('OperationMult')
- def work(self, a, b): self.result = a * b
- class Executor(object):
- def __init__(self, _type):
- self.operator = _type()
- def pr(self, a, b):
- self.operator.work(a, b)
- print(str(self.operator.get()))
- e1 = Executor(OperationSum)
- e1.pr(5, 6)
- e2 = Executor(OperationMult)
- e2.pr(5, 6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement