This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Strategy Pattern
Posted by Bill Venners on March 25, 2000 at 3:35 PM
> Hi > I'm trying to model a system in which I have some set of Algorithms. > In this system I want to provide a standard Interface to these algorithms. SO that I can maintain a > collection of such algorithms and also hide the Algorithm specific data. > My problem is that These Algorithm have different kind(and number) of inputs > thus it becomes really difficult to put them with a single interface. > It would be greatly helpful if you can give some suggesion with an example. > This sounds like a good candidate for the Strategy Pattern from the Gang of Four Design Patterns book. What you could do is define an interface or abstract class that has one or more methods that run the algorithm. You can then define a class for each actual algorithm, that either implements the interface or extends the abstract class. The constructors for those classes can take the data that is unique to each algorithm. I'm not certain if this approach will work in your situation, because I don't know the details. But perhaps it will help stimulate your thinking. bv
Replies:
|