Exforsys

Online Training

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 ...


Go Back   Exforsys > Testing > Software Patterns

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-12-2005, 12:05 PM
gamesmeister
Guest
 
Posts: n/a
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-12-2005, 02:30 PM
Shashank
Guest
 
Posts: n/a
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #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.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:34 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.