Re: Searching OO Associations with RDBMS Persistence Models
- From: Robert Martin <unclebob@xxxxxxxxxxxxxxxx>
- Date: Sun, 28 May 2006 11:47:39 -0500
On 2006-05-01 14:22:14 -0500, "Richie" <richie.chauhan@xxxxxxxxx> said:
Hi all,
What is the best way to implement the following search
Give me all companies that start with "Micro" in Seattle, Washington
Class Company
{
String companyName;
Set locations;
public void addLocation(location)
{};
}
In the database world, this is a simple join across two tables.
What is the correct correlation of this in a Object Oriented World.
The word "Correct" is probably inappropriate. There are a number of correct ways. One good way is to create a new class named CompanyQuery that has methods that represent the kinds of queries you'd like to do.
public class CompanyQuery {
List<Company> getCompaniesThatStartWith(String prefix){...}
}
Indeed, if you made this into an interface, then you could implement it many different ways. Then the fact that you were using an RDB would be irrelevant to the rest of the program. (a good thing!)
--
Robert C. Martin (Uncle Bob) | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc. | blog: www.butunclebob.com
The Agile Transition Experts | web: www.objectmentor.com
800-338-6716 |
.
- Follow-Ups:
- References:
- Prev by Date: Re: sequence diagram for observer pattern
- Next by Date: Re: Searching OO Associations with RDBMS Persistence Models
- Previous by thread: Re: Searching OO Associations with RDBMS Persistence Models
- Next by thread: Re: Searching OO Associations with RDBMS Persistence Models
- Index(es):