-2

In my current work, I am facing a problem in deciding which pattern to go for. So I need help in solving the problem.

There is a central class which receives all callbacks for one application. Based on these callbacks, the application changes its states and screens.

Now there are around 15 different status variables that get changed and for every status there are 4-5 average different values that can received. The combination of each value of status received can define application state. I am not very keen on going for State design pattern since there will be lot of states.

Can some one suggest me which design pattern I should go for.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Amit Deshpande
  • 19,001
  • 4
  • 46
  • 72
  • I am reminded of Colossal Cave... – Alnitak Mar 23 '12 at 11:02
  • 1
    It's difficult to advise unless you're able to post some code snippets. Also, your way of thinking sounds wrong - People don't tend to write the application and then fit it to a pattern just for the sake of it. – Adamski Mar 23 '12 at 11:03
  • The central class sounds like a candidate for the Front Controller pattern. – Perception Mar 23 '12 at 11:12
  • A guess would be that part of those states belong to business rules, so a mini rule engine might be appropriate. I a similar case I used XML. Maybe JAXB. So maybe the duck typing anti-pattern. The question is the reporting/documentation of these state transitions. – Joop Eggen Mar 23 '12 at 11:28
  • Thanks all . This example fits my problem [State Design pattern](http://stackoverflow.com/questions/2057752/design-pattern-problem-involving-n-states-and-transitions-between-them) – Amit Deshpande Mar 23 '12 at 12:04

3 Answers3

0

Maybe the Observer design pattern will do?

npinti
  • 51,780
  • 5
  • 72
  • 96
0

Since, the problem statement you mentioned involves maintaining state of an applicaiton, I would prefer Command Pattern

Rockstart
  • 2,337
  • 5
  • 30
  • 59
0

"I am not very keen on going for State design pattern since there will be lot of states."

This is exactly why you should be using the state pattern, to organize the different sets of states/behaviors. If you only had two states, it might be over-engineering. The more you have, the more you need to use it.

If each of these states is distinct and the response to the stimulii (callbacks) differs based on this state then the State pattern is appropriate.

tcarvin
  • 10,715
  • 3
  • 31
  • 52