fork download
  1. # your code goes here#coding: utf-8
  2. """
  3. Типы строя
  4. """
  5. class Culture:
  6. """
  7. Культура
  8. """
  9. def __repr__(self):
  10. return self.__str__()
  11.  
  12. class Democracy(Culture):
  13. def __str__(self):
  14. return 'Democracy'
  15.  
  16. class Dictatorship(Culture):
  17. def __str__(self):
  18. return 'Dictatorship'
  19.  
  20. """
  21. Само правительство
  22. """
  23. class Government:
  24. culture = ''
  25. def __str__(self):
  26. return self.culture.__str__()
  27.  
  28. def __repr__(self):
  29. return self.culture.__repr__()
  30.  
  31. def set_culture(self):
  32. """
  33. Задать строй правительству : это и есть наш Фабричный Метод
  34. """
  35. raise AttributeError('Not Implemented Culture')
  36.  
  37. """
  38. Правительство 1
  39. """
  40. class GovernmentA(Government):
  41. def set_culture(self):
  42. self.culture = Democracy()
  43.  
  44. """
  45. Правительство 2
  46. """
  47. class GovernmentB(Government):
  48. def set_culture(self):
  49. self.culture = Dictatorship()
  50.  
  51. g1 = GovernmentA()
  52. g1.set_culture()
  53. print (str(g1))
  54.  
  55. g2 = GovernmentB()
  56. g2.set_culture()
  57. print (str(g2))
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
Democracy
Dictatorship