When we model position of things in code, we often put the position within the thing being modeled - car, game character, window, etc. So you can do things like: aCar.position - but I think that might be conceptually wrong and have been thinking that for a long time but haven't had much chance to explore the idea.
The idea of putting the responsibility for (eg.) location of each object within the world into the world itself seems to fit better with reality, too. After all, in our physical reality there's rules that "the world" imposes on things within it. One big one is that only one physical object (atom or what-have-you) can exist in a given location in space at a given time. Having the location of an atom in space be stored in the atom itself would seemingly make it a lot more difficult to make sure that rule goes unbroken and, arguably, can't be how the universe works as we seemingly cannot "see" location encoded within physical objects in our universe (that I know of). Therefore the location of a thing is probably "stored" within the fabric of the universe itself...
Anyway... If you write up your experiences, please post them to HN - I'm betting they'd be interesting!
When we model position of things in code, we often put the position within the thing being modeled - car, game character, window, etc. So you can do things like: aCar.position - but I think that might be conceptually wrong and have been thinking that for a long time but haven't had much chance to explore the idea.
But of course, you can have this API and delegate the responsibility of calculating the position:
class Street {
has 'cars';
method add_car(){
$car = Car->new( street => $self );
$self->cars->add($car);
return $car;
}
}
class Car {
has 'street';
method position() {
$self->street->position_of($self)
}
}
Now, given a random Car, you can still ask "$car->position", but the actual calculation is handled by something else.
(The deeper issue here is how consumers of Car are not coupling themselves to a particular position-calculation strategy. Change the storage of the position value from the Street to the Car, and consumers are none the wiser. This is the point of OOP.)
When we model position of things in code, we often put the position within the thing being modeled - car, game character, window, etc. So you can do things like: aCar.position - but I think that might be conceptually wrong and have been thinking that for a long time but haven't had much chance to explore the idea.
The idea of putting the responsibility for (eg.) location of each object within the world into the world itself seems to fit better with reality, too. After all, in our physical reality there's rules that "the world" imposes on things within it. One big one is that only one physical object (atom or what-have-you) can exist in a given location in space at a given time. Having the location of an atom in space be stored in the atom itself would seemingly make it a lot more difficult to make sure that rule goes unbroken and, arguably, can't be how the universe works as we seemingly cannot "see" location encoded within physical objects in our universe (that I know of). Therefore the location of a thing is probably "stored" within the fabric of the universe itself...
Anyway... If you write up your experiences, please post them to HN - I'm betting they'd be interesting!