Guest User

Untitled

a guest
Jan 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. class Mixin:
  2. def __init__(self, *args, **kwargs):
  3. pass
  4.  
  5. class Valuation:
  6. def __init__(self):
  7. self._qty = 0
  8.  
  9. def qty(self):
  10. print('Valuation::qty')
  11. return self._qty
  12.  
  13. class SubscriptionValuation:
  14. def __init__(self):
  15. self._qty = 0
  16.  
  17. def qty(self):
  18. print('SubscriptionValuation::qty')
  19. return self._qty
  20.  
  21. class Valuatable(Mixin):
  22. def __init__(self, *args, **kwargs):
  23. print("Enter Valuatable")
  24. super().__init__(**kwargs)
  25. self.valuation = (kwargs.get('valuation') or Valuation)()
  26. print("Leave Valuatable")
  27.  
  28. def qty(self):
  29. return self.valuation.qty()
  30.  
  31. class Summation:
  32. def __init__(self):
  33. self._total = 0
  34.  
  35. def total(self):
  36. print('Summation::total')
  37. return self._total
  38.  
  39. class SubscriptionSummation:
  40. def __init__(self):
  41. self._total = 0
  42.  
  43. def total(self):
  44. print('SubscriptionSummation::total')
  45. return self._total
  46.  
  47. class Summable(Mixin):
  48. def __init__(self, *args, **kwargs):
  49. print("Enter Summable")
  50. super().__init__(**kwargs)
  51. self.summation = (kwargs.get('summation') or Summation)()
  52. print("Leave Summable")
  53.  
  54. def total(self):
  55. return self.summation.total()
  56.  
  57. class Form(Valuatable, Summable):
  58. def __init__(self, *args, **kwargs):
  59. self.id = kwargs.get('id') or ''
  60. self.name = kwargs.get('name') or ''
  61. super().__init__(*args, **kwargs)
  62.  
  63. f1 = Form(name='normal 1', valuation=Valuation)
  64. print(f1.qty())
  65. print(f1.total())
  66. f2 = Form(name='subscription 2', valuation=SubscriptionValuation, summation=SubscriptionSummation)
  67. print(f2.qty())
  68. print(f2.total())
Add Comment
Please, Sign In to add comment