25
loading...
This website collects cookies to deliver better user experience
class LightBulb:
_state = 'OFF' # initial state of bulb
def onOff(self, switch):
if switch == 'ON':
self._state = 'ON'
elif switch == 'OFF':
self._state = 'OFF'
else:
continue # if we get wrong input
State
classes. The original class keeps a reference to a state object based on its current state rather than using conditional statements to implement state-dependent functionality.