79362190

Date: 2025-01-16 15:41:40
Score: 1.5
Natty:
Report link

The previous answers are useful, but I'll add some more for those who find this later.

The correct way to solve the problem is exactly what the question poster did. The only other thing I would do is changing the name of the function from addPassenger to addPassengerToBus (or boardBus).

Adding a passenger to the bus should change the fullness of the bus. You would never want to have someone added to the bus without calculating the change in bus fullness. From the "business" perspective (the business of busses) it is one thing.

What is not one thing, is the exact numerical tipping points, which should be calculated via it's own function and called whenever a passenger is added.

Had adding people to the bus truly been independent of calculating the fullness of the bus, then the thing to do would be to split the functions and have the method which calls addPassenger now call both methods directly.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: TobadiahStane