Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD - Domain Model Problem

I have i discussion with a partner we have this scenario:

**Publishers root entity 
Advertiser root entity**

Each of those entities share common info : Email, BillingAddress, NormalAddress, sex, SSN, etc.

I have decide: Person Entity with a Value object Address and rest of properties. This way if i want to access a specific info about a Person (email, sex, dateofbird) i dont have to go through publisher or advertiser root entities to get it (treat Person as an aggregate root).

Sample: **Person.BillingAddress.Address1 :
        Person.BillingAddress.Address2 :
        Person.BillingAddress.POBOX :
        Person.Email :
        Person.Sex**

My teammate propose to to do it using abstract class, advertiser and publisher inherits from Person abstract class in order to have all common properties.

What is the best way to do it?. If you have one please guide us.

Thanks, Pedro de la Cruz

like image 581
Pedro de la Cruz Avatar asked Jul 12 '26 21:07

Pedro de la Cruz


2 Answers

I think that you are right. Inheritance just make sense when the behaviour is common (some thing is a kind of other thing), then Person isnt a kind of OTHER THING just because the properties are similars. It isnt code reuse.

like image 183
irobson Avatar answered Jul 15 '26 15:07

irobson


You should favour composition over inheritance.

Your design is better because otherwise if at some point you need to introduce something else in this hierarchy (e.g make your root entities AuditableEntity) you won't be able to do so (unless your language supports multiple inheritance - which is bad).

like image 20
cherouvim Avatar answered Jul 15 '26 15:07

cherouvim