I'm trying to model a basic scenario involving a Person and a Seat. A Person has a Status property: Sitting or Standing. A seat has a Seated property that specifies the Person that is currently sitting in it. Also, a Seat is special in that it only "accepts" certain people to sit in it. I know it sounds strange for a Seat to "accept" someone, but just imagine it prefers certain people over others.
Following "Tell, Don't Ask," How should I design the Person and Seat objects so that a Person can sit down in a Seat only when the Seat "accepts" him and also have his status changed to Sitting. My first thought was that a Person should have a SitDown method as follows:
Person.SitDown(Seat seat);
But this seems like it would require the Person class to inspect the state of the Seat before sitting in it, as well as having to update the Seat's Seated property (instead of the Seat updating the property itself):
// inside the Person class
void SitDown(Seat seat) {
if (seat.AcceptsPlayer(this)) {
seat.Seated = this;
this.Status = Sitting;
}
}
It seems better to have the Seat class handle seating a person:
Seat.SeatPerson(Person person);
// inside Seat class
void SeatPerson(Person person) {
if (IsAccepted(person)) {
this.Seated = person;
person.Status = Sitting;
}
}
But this still requires the Seat to change the person's status. Is this the way that the person's status should be updated? Should only a Person be able to change his status? How would you model this simple scenario?