문제

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

도움이 되었습니까?

해결책

You are thinking about your domain in therms of your database. This is not recommended.

Supplier Entity that mirrors the above Customer aggregate

This suggests you are missing a concept in your domain. What does this "mirroring" mean for your domain expert? If indeed there is a relationship between them it should be explicitly modeled.

You say that "Customers -> Emails is a many to many relationship". Is it meaningful for your domain that an email is shared by multiple customers? If yes that again you are probably missing a concept. Check what your domain expert has to say about this relationship. If it's not really many to many but one to many than maybe the email is a value object that the customer entity "owns". Now if the customer owns the email or address you can delete it (or act upon it) without any restrictions.

One of the hardest things about DDD is that you always end up trying to share entities between aggregates. Don't. You defeat the hole point of an Aggregate - the consistency boundary. Instead, with the help of your domain expert identify the missing concepts that will clarify the boundaries between ARs.

I know it all sound abstract ( i've asked questions like this in the past ) but the truth is that only you domain expert can help you model the domain better.

And as a last advice - re(-re X 100)reading Eric Evans's book usually helps :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top