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
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With