Question

I typically try and avoid bidirectional relationships at all costs. Recently I've been trying to follow a more domain centric design philosophy and I'm looking for advice in the best way to solve a specific problem.

I am implementing a basic 2d grid. There are 3 basic classes, Item, Tile (has a list of Items), and World (has a 2d array of Tiles).

I am struggling with where to put the move() method which moves an item from one tile to a neighboring tile. My initial inclination would be to place the move method in the Item class since it is the item that is actually moving.

However, that would create a circular dependency. In the past I always worked with dumb objects in which case the move() method was in a higher layer (some kind of WorldManager or MoveManager) which knows about both tiles and items. I'm interested in what proposals others might have that can avoid the circular dependency while maintaining the domain-centric philosophy.

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top