Guest User

Untitled

a guest
Apr 26th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2.  
  3. RED = 'RED'
  4. YELLOW = 'YELLOW'
  5. GREEN = 'GREEN'
  6.  
  7.  
  8. class Light(ABC):
  9. @property
  10. @abstractmethod
  11. def color(self):
  12. pass
  13.  
  14. @staticmethod
  15. def create_light(color):
  16. if color == RED:
  17. return Red()
  18. elif color == YELLOW:
  19. return Yellow()
  20. elif color == GREEN:
  21. return Green()
  22.  
  23.  
  24. class Red(Light):
  25. color = RED
  26.  
  27.  
  28. class Yellow(Light):
  29. color = YELLOW
  30.  
  31.  
  32. class Green(Light):
  33. color = GREEN
  34.  
  35.  
  36. r = Light.create_light(RED)
  37. print(r.color)
Add Comment
Please, Sign In to add comment