Re: Retrieving unnecessary data



On Feb 14, 11:26 am, ShaneLM <shane.nieberg...@xxxxxxxx> wrote:
I'd like some advice on how to structure my classes. Let me use an
example to convey my situation. Pretend I am modeling a Car.

Class Car
{
        String make;
        String model;
        Enum color;
        List<People> passengers;

}

My problem arises because sometimes I'm just interested in the stats
of the car, and not the people in the car. Although in other
situations I do care about the people in the car.

If I'm writing a database access method, say GetCar(), I feel like
time is wasted retrieving info about the passengers that I will never
use in some situations. So I feel like I have a few alternatives:

A)      Return the class with all fields filled out, regardless of whether
they will be used or not. This is OO, right?
B)      Create overloads for GetCar where I indicate whether I want all
fields filled out for me. Ex: GetCar(bool fill_passengers);
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);
D)      Make 2 classes - Car and CarWithPassengers (that can derive from
Car).

Does that make sense? I know it doesn't sound like retrieving a
passenger list is expensive, but I'm trying to keep this example
simple. Consider if the People class had lots of nested classes inside
of it, and all we wanted to know was the person's name? Same situation
occurs...

Which alternatives do you prefer? Is there anything else you would
suggest?

Thanks so much!!
Shane

These are the kinds of problems one encounters when they try to use
OOP to model domain nouns. Modeling domain nouns for business apps is
a road to bloat, hell, or both.

And, I've encountered OO fans who agree with me on this point. They
feel that OO is best used for things like GUI's and reporting idioms,
not domain nouns.

Let the DataBase model the domain nouns (business things) and get
*only* what you need from the DB for any given task. Life will be
simpler.

-T-
oop.ismad.com
.



Relevant Pages

  • Re: Retrieving unnecessary data
    ... Pretend I am modeling a Car. ...    String model; ... First let me point out that you are not modeling a class. ... No, this is database thinking, not OO. ...
    (comp.object)
  • Re: Best Beater Cars...
    ... rather than take over my 2006 Honda Accord ... a big 80s rwd car like a Crown Vic or the ...   All I do is change the oil. ... I'll probably have the brakes done when I get those replaced. ...
    (rec.sport.football.college)
  • Re: American made electric car
    ...   3) Ya think the Eurotrash car will pass safety standards? ... What about a heater (runs off hot engine coolant in IC cars) and air ... Compare to Stooopid "Smart Car". ... What's good for General Motors is good for America! ...
    (sci.physics)
  • Re: Fraudulent Nation?
    ... How about those used car buyers? ... The "soft underbelly" of this whole scheme is that frequently dealers ...     "The dozen banks now receiving the biggest rescue packages, ...
    (misc.invest.stocks)
  • Re: Ensoul/Lynn AGAIN
    ...   But I sat at the pc and answered every one ... other side of the car. ...  and then called the local police. ...
    (alt.support.chronic-pain)