Retrieving unnecessary data



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
.



Relevant Pages

  • Re: Aggregation vs composition
    ... >> class Car { ... >destroying Engine, in such a way that everything is the same as before. ... >responsibility for the part. ...
    (comp.object)
  • Re: Help With ICloneable And Deep Copy
    ... a completely new copy of the example class car below. ... with a shallow copy where changing NewCar also changes OldCar. ... Dim OldCar As New Car ... Dim oClone As New Car ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Help With ICloneable And Deep Copy
    ... a completely new copy of the example class car below. ... Public Function Clone() As Object Implements ICloneable.Clone ... Dim oClone As New Car ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Checking objects static or not
    ... > - extends JFrame ... > game" button, if yes, declare a Jframe and initialize it with the Game ... For example thinking of cars, you might have a class Car. ...
    (comp.lang.java.programmer)
  • Help With ICloneable And Deep Copy
    ... a completely new copy of the example class car below. ... with a shallow copy where changing NewCar also changes OldCar. ... Dim OldCar As New Car ... Public Property ColorAs String ...
    (microsoft.public.dotnet.languages.vb)