View Single Post

  #3 (permalink)  
Old 01-13-2005, 04:56 AM
Anders Pedersen
Guest
 
Posts: n/a
Re: Mismatched parameters in a Strategy Pattern


"gamesmeister" <gerard@gmsoftware.co.uk> wrote in message
news:1105545906.991049.79520@z14g2000cwz.googlegroups.com...
> [Strategy pattern text snipped]
> The problem is, while both these implementations are logically
> performing the same function, both need different parameters to perform
> the task. This means my interface will need both versions of the
> method, which means in turn both classes will need both too. I'm pretty
> sure that's not right!
> I'm thinking one possibility might be to have a separate class to hold
> the parameters, and pass an instance of that into each method. Is that
> a good or bad approach?
> Alternatively, am I approaching this in completely the wrong way - is
> there another pattern I should be using?


The strategy pattern will work best if you can define the interface at
the right level of abstraction, so that it can be implemented in all the
expected ways. You may need to rethink parts of your design.

Alternatively, define the interface with the union of all parameters needed
by all expected implementations. Some implementations will then just
ignore some parameters.

If this advice doesn't help you, maybe post a followup with more detail
about the problem.

Regards,
--Anders.


Reply With Quote