I have a very specific issue in mind, regarding on how to implement data models using instantiable classes. For example, let's say I have a list of cars in my database, and somewhere in my code I will have both the need to load a specific car, and to load all of the cars.
Does it make more sense to create a class Cars
where $cars = new Cars;
would return all cars, and when I need a specific car, I would call a static method Cars::getCar($id)
?
Or vice-versa, have a class Car
where $car = new Car($id)
would return a specific car, and when I need all of them, I would call a static method Car::getAll()
?
In both these cases, these static methods would in this case return simple arrays?
Would it make more sense (but it seems very impractical) to have both an instantiable class Car
and an instantiable class Cars
?
Is there yet another, ultimately better way?