I have an aggregate root named Building.
In the Building class, I have three methods for adding, updating, and deleting a building.
- When adding a building, I create a new Building object.
- When updating, I create a new version of the Building.
- When deleting, I check if the entity has no related dependencies before allowing deletion. I also have a BuildingService that handles these operations.
Inside Building, I have an entity named Floor, which is also an entity root. The Building class contains a list of floors, and I have three methods for adding, updating, and deleting floors within this list. Additionally, I have a FloorService that manages the Floor entity.
Now, I want to add an entity under Floor called Unit. Unit should be structured similarly to Floor—it will be an entity root. However, I am confused about how to implement the add, update, and delete methods for Unit.
Building manages Floor, even though Floor is an entity root. Unit should be managed by Floor, but since Floor is already an entity root, how can I allow Floor to manage Unit while maintaining DDD best practices? I want to handle the Unit entity similarly to how Floor is handled within Building, but I am unsure how to structure this correctly.
What is the best approach to managing Unit under Floor while ensuring consistency and adhering to DDD principles?