-
Notifications
You must be signed in to change notification settings - Fork 116
Open
Description
berry.exe state.be is working well
but if i call berry and import state.be
than an redefinition error comes.
import "state.be" as state
syntax_error: state.be:17: redefinition of 'OffState'
stack traceback:
stdin:1: in functionmain
#- Step 1: Define the State Interface
class State()
def handle(context):
pass
end
end
-#
# Step 2: Create Concrete States
var OffState = nil
class OnState
def handle(context)
print("Light is already ON. Switching it OFF now.")
context.state = OffState()
end
end
class OffState
def handle(context)
print("Light is OFF. Switching it ON now.")
context.state = OnState()
end
end
# Step 3: Create the Context
class LightSwitch
var state
def init()
self.state = OffState()
end
def press()
self.state.handle(self)
end
end
# Testing the FSM
switch = LightSwitch()
switch.press() # Expected: "Light is OFF. Switching it ON now."
switch.press() # Expected: "Light is already ON. Switching it OFF now."
switch.press() # Expected: "Light is OFF. Switching it ON now."
Metadata
Metadata
Assignees
Labels
No labels