Parametrized Strategy Pattern

Posted by ott on Stack Overflow See other posts from Stack Overflow or by ott
Published on 2010-04-18T11:21:28Z Indexed on 2010/04/18 11:23 UTC
Read the original article Hit count: 545

I have several Java classes which implement the strategy pattern. Each class has variable number parameters of different types:

interface Strategy {
     public data execute(data);
}

class StrategyA implements Strategy {
     public data execute(data);
}

class StrategyB implements Strategy {
      public StrategyB(int paramA, int paramB);
      public data execute(data);
}

class StrategyB implements Strategy {
      public StrategyB(int paramA, String paramB, double paramC);
      public data execute(data);
}

Now I want that the user can enter the parameters in some kind of UI. The UI should be chosen at runtime, i.e. the strategies should be independent of it. The parameter dialog should not be monolithic and there should be the possibility to make it behave and look different for each strategy and UI (e.g. console or Swing).

How would you solve this problem?

© Stack Overflow or respective owner

Related posts about java

Related posts about design-patterns