vendredi 29 juin 2018

In the State Pattern as outlined in the Gang of Four textbook can the ConcreteState objects make changes to the context in which they reside?

This is a quote that I might be misinterpreting from this section of the book Design Patterns, Elements of Reusable Object-Oriented Programming.

• A context may pass itself as an argument to the State object handling the request. This lets the State object access the context if necessary.

If the ConcreteState is passed the context from a Request(this); is that State allowed to make changes to the context itself?

In the example I'm working on the Context is a WindowsForm in C#, with states such as FormStart and FormStop. I would like to make changes so that when the state is changed some of the buttons in the form are disabled/greyed out. As far as I know the constructor of the ConcreteState could be passed the context as an argument and then the state could make changes to the context.

Let me know what you think. I'm still a beginning programmer working on making GUI apps that are functional and reusable from a code perspective before working on tweaking the UI and making the front end pretty.

Aucun commentaire:

Enregistrer un commentaire