What you missed is the concept of the Value object. Value objects are small, immutable objects with a value in the corresponding domain.
I donβt know the specifics of your domain, but looking at your Job object, there may be a value JobDescription object that looks like this:
class JobDescription { public JobDescription(string position, string requirements, string responsibilities) { Position = position; Requirements = requirements; Responsibilities = responsibilities; } public string Position {get;} public string Requirements {get;} public string Responsibilities {get;} }
This is C # code, but I think the idea should be clear, regardless of the language you use.
The basic idea is group values, which makes sense in the corresponding domain . This means, of course, that value objects can also contain other value objects.
You should also make sure that value objects are compared by value and not by reference, for example. by implementing IEquatable<T> in C #.
If you reorganize your code with this approach, you will get fewer fields on your entity, so using the constructor installation (which is highly recommended) will be possible again.
Additional notes regarding your sample code that are not directly related to the question:
A domain model is everything, an entity is part of it. Therefore, your base class should be called Entity , not DomainModel .
You must make the fields of your class private and provide protected accessors where necessary to support encapsulation.
theDmi
source share