Dofactory.com
Dofactory.com
 Back to list
Views:   5.6K
Replies:  1
Archived

Design Pattern dilemma. Strategy seems wrong?

I would like some help/advice on a design pattern or similar I could use for my problem.

I have some shared functionality in my code and I use the Strategy pattern at present. I have a base class
named "ProjectSectionBase" and from here I have 2 derived classes, "ProjectSectionStandard" and "ProjectSectionSuperior".
Now the problem is that "ProjectSectionSuperior" has a lot of extra functionality than "ProjectSectionStandard" and I'm
finding that throughout my code i am calling methods like this:

DirectCast(_projectSection, ProjectSectionSuperior).DoSuperiorStuff

And I am also wrapping IF statements such as IF typeof(_projectSectio) is superior then.

It just feels like bad class design. Both standard and superior share a lot of common functionality but then Superior
has so much more functionality. Any advice would be greatly appreciated.

Neville Hargreaves, Jun 10, 2013
Reply 1
Neville:

What you describe is certainly not the Strategy Pattern. In Strategy all classes (of the strategy) have the same interface. 

What you have is inheritance. The 'superior' should derive from 'standard' and then possibly override some virtual functions and add some additional methods and behavior. I am not sure if there is another pattern that can help you. Perhaps the State pattern, but it all depends on your requirements. 

Since 'standard' and 'superior' are so very different you would ideally place a single IF statement somewhere in your logic and then have two entirely self-contained components that handle the particular situation. So, you apply some form of refactoring. 

Hope this helps. 


Deshaun Hyram, Jun 10, 2013
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.