This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Difference between strategy and template method patterns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Difference between strategy and template method patterns" Watch "Difference between strategy and template method patterns" New topic
Author

Difference between strategy and template method patterns

Nandita Yerramareddy
Greenhorn

Joined: Nov 02, 2008
Posts: 3
Hello All,

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
Nachiket Patel
Ranch Hand

Joined: Sep 16, 2007
Posts: 110
Hi, Nandita

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.

Regards,
Nachiket
[ November 04, 2008: Message edited by: Nachiket Patel ]

Before software can be reusable, it first has to be usable. - Ralph Johnson
Nandita Yerramareddy
Greenhorn

Joined: Nov 02, 2008
Posts: 3
Thank you Nachiket! for clearing my novice doubts . I guess now i have some clear idea on using patterns in an application.
 
 
subject: Difference between strategy and template method patterns
 
Similar Threads
Help any methodology or aproach to attack development of project
Grails 1.1 Web Application Development
basic terms
Passed SCJD with 137/155
Passed SCEA Part 2 - My experience