When modeling the interaction between two objects, I sometimes find myself considering which object should be active in the interaction and which should be passive, or whether the interaction should be managed by a third-party controller.
As an example let's assume we have an Item and a Container.
Three possible ways to handle the interaction between them could be.
- item.Drop(container)
- container.Store(item)
- StorageController.Store(item, container)
Assuming all 3 approaches (and several others) can be correct in a given situation, what kind of considerations do you make to reach the most sustainable design choice?
The question is intentionally generic as I'm interested in the general principles people apply when assigning roles to objects, particularly if the overall architecture is at its early stages and it's yet not clear the level of responsibility that each object will take over time.
Aucun commentaire:
Enregistrer un commentaire