Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Solution with State Design Pattern solution in Clear category for Multicolored Lamp by von.Oak
class LampState:
def switch(self):
self.__class__ = eval(self.following)
return self.__class__.__name__
class Green(LampState):
following = 'Red'
class Red(LampState):
following = 'Blue'
class Blue(LampState):
following = 'Yellow'
class Yellow(LampState):
following = 'Green'
class Lamp:
def __init__(self):
self.state = Yellow()
def light(self):
return self.state.switch()
July 14, 2018
Comments: