Difference between strategy and template method patterns
Joined: Nov 02, 2008
This is my first post on Javaranch and I have just started to implement patterns to an application. My Application is similar to EBay.
Here I am not sure if I have to use template pattern or strategy pattern to process search Listing.
If I use template than I have a template method which does basic search.
This method is defined in Manager class , Administrator class and User class. So every one have different kind of search options inside that template method, example admin will search for accounts, where as user will search for items.
If I use Strategy than I was thinking like i will write a basic search method where search is based on two types generic search and advanced search based on the entered item.
I am not sure as a designer which idea i should consider to make my search works similar to ebay search.
I was also thinking to use strategy pattern for the services( listing, selling, buying,bidding)
Can i combine template search and strategy services? I wanted to know if i following the right approach.
thanks in advance Nandita
Joined: Sep 16, 2007
You have to take decision yourself. No one can guide you with few lines of information. And please understand patterns are standard solution to the standard problem/situation (in design), you can apply any patterns to any problem/situation, But you have to see weather is this patterns is really for the design problem/situation. And you can merge any patterns, if it make sense to you. For example i used strategy patterns at three different places, but none of it is pure strategy. I changed it bit, but it's OK as it is making sense to me.
Even you can code in one class and still your search may works similar to ebay search, if you want.
I'll say go step by step. And evaluate (which patterns should be used) by yourself.