Re: Retrieving unnecessary data



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
.



Relevant Pages

  • Re: Retrieving unnecessary data
    ... Phlip - the Proxy design pattern is exactly what I'm looking for. ... Then you need to leave the passengers ... the method returns the stash. ...
    (comp.object)
  • Re: hi everyone!
    ... It started as just a pattern review site, ... Stash reduction contest. ... Recently James needed new trousers for camp, and for the trip to France he's on now, so he got: ...
    (alt.sewing)
  • Re: hi everyone!
    ... It started as just a pattern review site, ... Stash reduction contest. ...
    (alt.sewing)
  • Re: China dishes quilt finished!
    ... pattern for the interior of it. ... Louise, I had to buy the white/blue border toile fabric. ... rest was stash stuff that I had. ... You know those all floral dishes from England called chintz? ...
    (rec.crafts.textiles.quilting)
  • Re: Train missing stations!
    ... but I'm not sure I'd actually make an apology over the PA. ... see the point to unaffected passengers still on the train. ... pattern could have been done at Potters Bar. ... stop Potters Bar' when he realised his error. ...
    (uk.railway)