Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from abc import ABC, abstractmethod
- RED = 'RED'
- YELLOW = 'YELLOW'
- GREEN = 'GREEN'
- class Light(ABC):
- @property
- @abstractmethod
- def color(self):
- pass
- @staticmethod
- def create_light(color):
- if color == RED:
- return Red()
- elif color == YELLOW:
- return Yellow()
- elif color == GREEN:
- return Green()
- class Red(Light):
- color = RED
- class Yellow(Light):
- color = YELLOW
- class Green(Light):
- color = GREEN
- r = Light.create_light(RED)
- print(r.color)
Add Comment
Please, Sign In to add comment