WSK
WSK

Reputation: 6158

Can Entity Class be inherited from Value Object?

In my business domain an entity "CompanyPrefix" appears to extend a VO CompanyPrefixVO that keeps all business rules. No other class would be using this VO. As a good practice:

  1. should I extend CompanyPrefix from CompanyPrefixVO? or
  2. drop the VO and merge business rules into entity CompanyPrefix? or
  3. CompanyPrefix should only be associated with CompanyPrefixVO? or
  4. something totally different?

enter image description here

Upvotes: 0

Views: 1105

Answers (1)

Dennis Traub
Dennis Traub

Reputation: 51634

Inheritance can lead to many problems, first of all high coupling and strong dependencies which can hinder your domain model from evolving. I'd use composition instead. The Value Object can be part of the Entity.

That said I'd also ask a few questions: What kind of business entity would CompanyPrefix be? Is it not just part of a name or identifier? Does it have a lifecycle of its own, i.e. does it change its properties over time? Why does the prefix need an ID? Just for normalization (aka database details that don't belong in the domain model?)

I don't know your specific case but there simply might be a VO representing a company prefix as part of the company.

Upvotes: 1

Related Questions