Tony Johansson wrote:
> Hello!
>
> We have the two classes Person and Elevator.
> I just wonder method NewFloorRequest that set the floor that the elevator
> should go to which class should it belong to between Person and Elevator.
>
> [...]
> Which class would you thing is the best choice between Person and Elevator
> for method NewFloorRequest ?
> I hope you can give some motivation about you choice so I get a better
> understanding about why the selected class is the best choice.
Does it have to go into either? It seems to me that both the Person and
the Elevator class are entities existing within a large framework. In
particular, there is a broader "controller" object that should be
receiving requests from the Person and translating that into control for
the Elevator.
When you have just one Elevator object, you might be able to get away
with combining the controller and behavior logic into the same class,
but that doesn't leave the design much room to grow. Once you have
multiple Elevator instances, the controller will want to direct all
Elevator instances using broader information about the state of all
Elevator instances and all Person instances.
Putting the control logic into either the Person _or_ the Elevator will
force you into a situation where individual instances require too much
information about other instances, creating a dual role for that class
that violates the general goal of OOP that each object do one thing
well, rather than many things poorly.
Pete
|