
- Forum
- Testing
- Software Patterns
- Mismatched parameters in a Strategy Pattern
Mismatched parameters in a Strategy Pattern
This is a discussion on Mismatched parameters in a Strategy Pattern within the Software Patterns forums, part of the Testing category; I'm using what I think is a Strategy Pattern to perform the same process, but implemented in two different ways. ...
-
01-12-2005, 11:05 AM #1gamesmeister Guest
Mismatched parameters in a Strategy Pattern
I'm using what I think is a Strategy Pattern to perform the same
process, but implemented in two different ways. I therefore plan to
have an Interface with a single method, and two concrete classes that
inherit from the interface, each having a different implementation of
that method.
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?
I'm new at this, so any help is greatly appreciated.
Many thanks
Gerry
-
01-12-2005, 01:30 PM #2Shashank Guest
Re: Mismatched parameters in a Strategy Pattern
> I'm using what I think is a Strategy Pattern to perform the same
> process, but implemented in two different ways. I therefore plan to
> have an Interface with a single method, and two concrete classes that
> inherit from the interface, each having a different implementation of
> that method.
>
If this is strategy pattern will be more clear if you can quote your
actual scenario. Merely having to implement same interface may not qualify
your implementation to be using strategy pattern.
Also what do you mean by inheriting from the interface?
>
> 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!
>
>
Yeah, I guess that too. That something is wrongly designed.
> 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?
>
May be right depending on your context. But more obvious reply would be
that most possibly its wrong approach.
>
> Alternatively, am I approaching this in completely the wrong way - is
> there another pattern I should be using?
>
>
If you can explain your senario more clearly may be we can propose or may
discuss new approach.
regards,
Shashank
-
01-13-2005, 03:56 AM #3Anders Pedersen Guest
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.
-
Sponsored Ads

Reply With Quote





