Re: Retrieving unnecessary data
- From: Phlip <phlip2005@xxxxxxxxx>
- Date: Thu, 14 Feb 2008 12:11:45 -0800
Firstly, look up the "Active Record Pattern". It may have a C++ implementation. (Or you might move to a more productive language, too!)
ShaneLM wrote:
A) Return the class with all fields filled out, regardless of whether
they will be used or not. This is OO, right?
Why would that be "OO"??
B) Create overloads for GetCar where I indicate whether I want all
fields filled out for me. Ex: GetCar(bool fill_passengers);
That forces you to know, before getting the car, whether you'll want the passengers. That is a pernicious form of coupling.
C) Remove the passengers field, and retrieve them with another call.
I'd call GetCar(), and then if I want the passenger list, I'd call
GetPassengers(Car);
Why remove the field? Just leave it empty. It's private and encapsulated (right?), so nobody will know it doesn't match "reality" (whatever _that_ is!).
D) Make 2 classes - Car and CarWithPassengers (that can derive from
Car).
Having too many classes is not "OO"...
You need to look up the "Proxy Pattern". Then you need to leave the passengers and statistics NULL until you call GetPassengers or GetStatistics. (This is a major reason, in C++, to even _have_ Get methods!)
If those are NULL - or an empty list - then the system will read them from their database, and stash them.
Either way, the method returns the stash. This is a very common pattern. Subsequent calls to Get return the stash, until you destroy the Car object, or call a Reload() method on it.
--
Phlip
.
- Follow-Ups:
- Re: Retrieving unnecessary data
- From: ShaneLM
- Re: Retrieving unnecessary data
- References:
- Retrieving unnecessary data
- From: ShaneLM
- Retrieving unnecessary data
- Prev by Date: Re: Retrieving unnecessary data
- Next by Date: Re: Retrieving unnecessary data
- Previous by thread: Re: Retrieving unnecessary data
- Next by thread: Re: Retrieving unnecessary data
- Index(es):
Relevant Pages
|