Reputation: 17445
I'm thinking of implementing the state design pattern on an ASP .NET Webform.
The state would be determined by the query string passed to the page. Based on the state of the page, any action would call the method on the concrete implementation.
What I am trying to achieve is a page that can handle any number of different implementations of the same general functionality.
My questions are: Will this work? Does this sound like the right approach?
Upvotes: 1
Views: 1314
Reputation: 2030
Using a state pattern is an approach you can take for this, but honestly what your describing is part of what the MVC framework was designed to accomplish.
Edit:
MVP/MVC
Since the MVC Framework isn't an option then I would take a look at Model View Presenter pattern (MVP) with either the passive view approach or superviser approach as described here: http://www.martinfowler.com/eaaDev/SupervisingPresenter.html
We found that the passive view approach worked with a little adaptation for our legacy code to work out good for us.
Edit: Patterns:
In that case then which pattern you choose really depends upon what the business needs are.
State pattern:
State pattern is typically used for when you need to change the behavior of an object based upon its current state or the state of a relation to the object. A common usage of this pattern is with games when the behavior of the object depends upon which mouse cursor button is pressed.
http://en.wikipedia.org/wiki/State_pattern
Strategy pattern:
This pattern is good for when you need different implementation based upon a configuration. For example say you are defining an email system and you need to have a different implimentation based upon which email provider is being used to send the email.
http://en.wikipedia.org/wiki/Strategy_pattern
So State pattern could definetly be the right direction it just comes down to what the objective is and what behavior's your trying to meet.
What you'll often find with patterns is that they work well with eachother and you'll use multiple patterns in conjuction with eachother.
Upvotes: 2
Reputation: 3066
I think what you are suggesting would be a sound approach. The only advice I can really offer is to not get hung up on implementing the State Pattern perfectly. I think it would be perfectly acceptable to just have a switch which calls a method based on a query string value.
Upvotes: 0