Where should I put contextual data related to an Object that is not really a property of the object?
Posted
by RenderIn
on Stack Overflow
See other posts from Stack Overflow
or by RenderIn
Published on 2010-04-27T19:19:51Z
Indexed on
2010/04/27
19:23 UTC
Read the original article
Hit count: 297
I have a Car class. It has three properties: id, color and model.
In a particular query I want to return all the cars and their properties, and I also want to return a true/false field called "searcherKnowsOwner" which is a field I calculate in my database query based on whether or not the individual conducting the search knows the owner. I have a database function that takes the ID of the searcher and the ID of the car and returns a boolean.
My car class looks like this (pseudocode):
class Car{
int id;
Color color;
Model model;
}
I have a screen where I want to display all the cars, but I also want to display a flag next to each car if the person viewing the page knows the owner of that car.
Should I add a field to the Car class, a boolean searcherKnowsOwner
? It's not a property of the car, but is actually a property of the user conducting the search. But this seems like the most efficient place to put this information.
© Stack Overflow or respective owner