Hi,
I'm currently determining the entities, value objects and aggregates in a system. Say the following Entities have been identified:
Customer, CustomerEmail, Email, CustomerAddress, Address, AddressType
where Customers -> Emails is a many to many relationship, as is Customers -> Addresses (with an address type). These relationships are represented by the CustomerAddress and CustomerEmail relationship objects.
Initially I thought this was straight forward:
Entities: Customer, CustomerEmail, CustomerAddress Value Objects: Email, Address, AddressType
with a Customer being the aggregate root for an aggregate containing all the Entities and VO's above.
The problem I have (and this may just be as I am learning about the concepts of aggregates as I go forward) Say you have a Supplier Entity that mirrors the above Customer aggregate, using the same Address and Email value objects. In this case when a Customer is deleted the address and email shouldn't be deleted, as a Supplier, or even another customer may still be referencing them. I've seen a lot of documentation that suggests when an aggregate is deleted, everything within the aggregate boundary be deleted all at once. Am I right in assuming that this does not apply to Value Objects in the aggregate (ie. They are immutable... if we had a colour object green in a vehicle aggregate... you wouldn't delete the colour just because a car was removed) or should the email and address be there own entities (and aggregates) as two addresses, even though they may have the same attributes, are actual separate identities (ie. one is a Supplier Address, the other a customer address?)
Finally, if they are indeed Value Objects, how does one go about handling the case where they should be removed (No Suppliers or Customers remain referencing an address) if VO's can only be acted upon through their aggregate root?
Cheers,
Steve