design-patterns
design-patterns copied to clipboard
Implement GetState at GumballMachine
This method is currently only implemented at the TestingGumballMachine
for test purposes as I was worried about allowing clients to change the state of the machine if they decided to call methods on the state objects themselves. To fix this, I could implement the Prototype Pattern
on each state so I can call Copy()
when returning the state to the client. There’s still a problem with the instance of GumballMachine
being kept at each state. I can recreate it defaulting to a NoOpGumballMachine
or something