Domain driven design – Address entity / value

domain-driven-design

I have an address as part of my domain. The address keeps information about country, city, zipcode, street and housenumber. It is used in multiple places – a company can have an office address, invoicing address and/or correspondence address; transports have addresses at start, middle and end points; couple of other places, too.

I'm wondering how to correctly handle this DDD-way. Should address be a value object, an entity or an aggregate root? I've seen similar questions but not surprisingly none of those corresponded well with my domain.

An address doesn't know how to validate itself – company's addresses can be initially almost empty and filled later, but transport's addresses should be always complete. So generally it depends on the object containing an address, not on the address itself.

Next thing is that address of one company is completely independent from addresses in other companies – event if they are the same in terms of location. Also, changing company's address doesn't mean replacing it with another – it is just an update done to the current object. It also doesn't affect other any other address. Does that alone qualify address as an entity?

As address can't function on it's own, it shouldn't be AG, right?

Maybe address should be just an interface with CompanyAddress, TransportAddress etc. implementing it? They are following different rules after all…

I'd really appreciate your opinion about this. I feel like I'm missing something here, but can't quite figure out what exactly.

Best Answer

It sounds to me like you actually have two distinct objects here, Address and Location. A Location could be used to represent a corporate office or some other conceptual place, but an Address would be a value object that represents a physical location. An Address never changes, but the Address property of a Location can be changed from one Address value object to another with an appropriate event.

Related Topic