File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Mark's criteriaString builder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Mark Watch "Mark New topic
Author

Mark's criteriaString builder

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Mark had this to say in the huge Connection lock/unlock thread (which was a very good read BTW):
"The points I lost was because I added two methods to the Data class that should have been in the CriteriaFindBuilder class..."
Glad I saw this. I've got
public String getFormattedCriteriaString(
String[][] fieldsAndValues) in Data. Was patting self on back til I saw Mark's post.
Question is: doesn't this method have a good home in Data? Data requires this format, and so should offer this formatting service.
Also, what were your string builder methods, Mark? Is there a more eloquent way to provide raw info to a string builder method than a 2-level array?
p.s. started coding the assignment in earnest just last week and have come to LOVE this site!
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I too like to know the reasons behind having CriteriaFindBuilder class instead of two methods in the Data.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
I think I can answer for Mark (he is on vacation to Mumbai ), -- each class should focus on the specific purpose. The criteria building (parsing, storing the key-value entries in some data structure, etc) have nothing to do with Data, whose purpose is to describe Data. But since we need the criteriaFind() implemented in data, the criteria building functionality should be isolated in a helper class.
Eugene Kononov.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Eugene -- thanks. Sounds logical. Mark is on vacation in Mumbai???
Matthew Comer
Ranch Hand

Joined: Aug 10, 2001
Posts: 37
The GRASP patterns say something about this - your are looking for HIGH cohesiveness and LOOSE coupling. So, the functions provided by a class should be HIGHLY COHESIVE, i.e. related to a single purpose or objective and LOOSELY COUPLED to other classes.
So, the question is this: What does the parsing of query criteria have to do with the maintenance of a flat file database? Well, not much. To build both of these behaviors into a single class would NOT lead to high cohesion within the class.
It is important to note though that putting this behavior in a seperate class should be done in such a way as to keep COUPLING LOW, i.e. don't design CriteriaBuilder in such a way that it is highly dependant on the internal implementation or data structures of the Data class.
Matt
Arup Chowdhury
Greenhorn

Joined: Jan 20, 2002
Posts: 10
CriteriaBuilder/Finder method will be using some kind of an Algorithmn. Instead of directly putting the algoritmn in the Data class, I have created a criteriaFinder class to the work.
Advantages is loose coupling between the Data class and the Algorithm used, and also ability to add and remove algorithms.
This is a combination of Functor Pattern and Strategy Pattern
Regards
Arup
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Mathew, Arup, Thank you for the explanation.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks all for great explanations of why and how. Makes sense. This site is a great resource.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Now aren't I a great Ventriloquist?
I am back from Mumbai, and I must say the weather has been a downpour of work issues.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Well, hard work now pays off for the laziness in the future.
Eugene.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I've noticed a number of vacations to Mumbai mentioned in other threads. Had not realized that Mumbai is such a popular tourist destination (at least no more so than Chicago, IL).
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I go to Mumbai when it is too expensive to vacation in Detroit.
Mark
[ June 21, 2002: Message edited by: Mark Spritzler ]
 
 
subject: Mark's criteriaString builder
 
Similar Threads
Unlock
Mark, you might find this interesting
Setters
Platform Independent Command Line
warning includeantruntime was not set