Do Rich Domain Models mean large domain classes are acceptable?Scaling a rich domain modelTechniques for dealing with anemic domain modelWhen to use domain event vs double dispatchHow Single Responsibility Principle relates to anemic/rich domain model?Can a “rich domain model” violate the Single Responsibility Principle?Anemic domain model from the aspect-oriented programming point of view. Yet anemic?Repository pattern and mapping between domain models and Entity FrameworkDomain model or base type in find method?Delegating Domain Model Behaviour outside of EntityUsing app-level settings in rich domain models
Computer name naming convention for security
Array or vector? Two dimensional array or matrix?
What factors could lead to bishops establishing monastic armies?
Why do most airliners have underwing engines, while business jets have rear-mounted engines?
Why no parachutes in the Orion AA2 abort test?
What is the meaning of "prairie-dog" in this sentence?
Are host configurations in the SSH config merged?
Is a lowball salary then a part-time offer standard Japanese employment negotiations?
QR codes, do people use them?
What was the significance of Spider-Man: Far From Home being an MCU Phase 3 film instead of a Phase 4 film?
What was the nature of the known bugs in the Space Shuttle software?
Why is whale hunting treated differently from hunting other animals?
Will Jimmy fall off his platform?
How was the website able to tell my credit card was wrong before it processed it?
What are some bad ways to subvert tropes?
Any way to meet code with 40.7% or 40.44% conduit fill?
Category-theoretic treatment of diffs, patches and merging?
Sense of humor in your sci-fi stories
Taking my Ph.D. advisor out for dinner after graduation
Chilling juice in copper vessel
When is one 'Ready' to make Original Contributions to Mathematics?
The flying colours
Wouldn't putting an electronic key inside a small Faraday cage render it completely useless?
Are "confidant" and "confident" homophones?
Do Rich Domain Models mean large domain classes are acceptable?
Scaling a rich domain modelTechniques for dealing with anemic domain modelWhen to use domain event vs double dispatchHow Single Responsibility Principle relates to anemic/rich domain model?Can a “rich domain model” violate the Single Responsibility Principle?Anemic domain model from the aspect-oriented programming point of view. Yet anemic?Repository pattern and mapping between domain models and Entity FrameworkDomain model or base type in find method?Delegating Domain Model Behaviour outside of EntityUsing app-level settings in rich domain models
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have been reading a lot about SOLID and Domain Driven Design, then the debate on Anemic Domain Models and Rich Domain Models. I personally prefer the approach where an object will encapsulate its own domain knowledge, however as there is seemingly some difference of opinion I have some questions:
- Depending on the type of system, the main domain classes could get quite big, even if the logic of the methods are in separate classes. Is it generally acceptable that Single Responsibility Principal is ignored here, or is there a way of encapsulating say an Order with 50 fields and 50 methods, into a nice structure that does not leave you with a 1mb class, or is this acceptable given the encapsulation approach?
- Is there any guideline or rule of thumb on what should still go into a Domain Service or even Domain Factory, while trying to maintain an Rich Domain Model and encapsulation?
architecture domain-driven-design software-design solid-principles
add a comment |
I have been reading a lot about SOLID and Domain Driven Design, then the debate on Anemic Domain Models and Rich Domain Models. I personally prefer the approach where an object will encapsulate its own domain knowledge, however as there is seemingly some difference of opinion I have some questions:
- Depending on the type of system, the main domain classes could get quite big, even if the logic of the methods are in separate classes. Is it generally acceptable that Single Responsibility Principal is ignored here, or is there a way of encapsulating say an Order with 50 fields and 50 methods, into a nice structure that does not leave you with a 1mb class, or is this acceptable given the encapsulation approach?
- Is there any guideline or rule of thumb on what should still go into a Domain Service or even Domain Factory, while trying to maintain an Rich Domain Model and encapsulation?
architecture domain-driven-design software-design solid-principles
stackoverflow.com/search?q=Rich+vs+Anemic+Domain+Model
– Hooman Bahreini
Mar 25 at 22:02
DDD is a collection of design patterns and techniques that among other things prevent you ending up with 50 field monster classes. A domain model is not a lipstick you put on your pig of a database model. If you end up with a 50 field monster entity ask yourself what aggregate invariant that has to be transactionally consistent that depends on 50 pieces of data.
– abuzittin gillifirca
Mar 26 at 12:45
add a comment |
I have been reading a lot about SOLID and Domain Driven Design, then the debate on Anemic Domain Models and Rich Domain Models. I personally prefer the approach where an object will encapsulate its own domain knowledge, however as there is seemingly some difference of opinion I have some questions:
- Depending on the type of system, the main domain classes could get quite big, even if the logic of the methods are in separate classes. Is it generally acceptable that Single Responsibility Principal is ignored here, or is there a way of encapsulating say an Order with 50 fields and 50 methods, into a nice structure that does not leave you with a 1mb class, or is this acceptable given the encapsulation approach?
- Is there any guideline or rule of thumb on what should still go into a Domain Service or even Domain Factory, while trying to maintain an Rich Domain Model and encapsulation?
architecture domain-driven-design software-design solid-principles
I have been reading a lot about SOLID and Domain Driven Design, then the debate on Anemic Domain Models and Rich Domain Models. I personally prefer the approach where an object will encapsulate its own domain knowledge, however as there is seemingly some difference of opinion I have some questions:
- Depending on the type of system, the main domain classes could get quite big, even if the logic of the methods are in separate classes. Is it generally acceptable that Single Responsibility Principal is ignored here, or is there a way of encapsulating say an Order with 50 fields and 50 methods, into a nice structure that does not leave you with a 1mb class, or is this acceptable given the encapsulation approach?
- Is there any guideline or rule of thumb on what should still go into a Domain Service or even Domain Factory, while trying to maintain an Rich Domain Model and encapsulation?
architecture domain-driven-design software-design solid-principles
architecture domain-driven-design software-design solid-principles
edited Mar 25 at 21:17
TallTed
7,0552 gold badges15 silver badges28 bronze badges
7,0552 gold badges15 silver badges28 bronze badges
asked Mar 25 at 21:13
Tig2810Tig2810
293 bronze badges
293 bronze badges
stackoverflow.com/search?q=Rich+vs+Anemic+Domain+Model
– Hooman Bahreini
Mar 25 at 22:02
DDD is a collection of design patterns and techniques that among other things prevent you ending up with 50 field monster classes. A domain model is not a lipstick you put on your pig of a database model. If you end up with a 50 field monster entity ask yourself what aggregate invariant that has to be transactionally consistent that depends on 50 pieces of data.
– abuzittin gillifirca
Mar 26 at 12:45
add a comment |
stackoverflow.com/search?q=Rich+vs+Anemic+Domain+Model
– Hooman Bahreini
Mar 25 at 22:02
DDD is a collection of design patterns and techniques that among other things prevent you ending up with 50 field monster classes. A domain model is not a lipstick you put on your pig of a database model. If you end up with a 50 field monster entity ask yourself what aggregate invariant that has to be transactionally consistent that depends on 50 pieces of data.
– abuzittin gillifirca
Mar 26 at 12:45
stackoverflow.com/search?q=Rich+vs+Anemic+Domain+Model
– Hooman Bahreini
Mar 25 at 22:02
stackoverflow.com/search?q=Rich+vs+Anemic+Domain+Model
– Hooman Bahreini
Mar 25 at 22:02
DDD is a collection of design patterns and techniques that among other things prevent you ending up with 50 field monster classes. A domain model is not a lipstick you put on your pig of a database model. If you end up with a 50 field monster entity ask yourself what aggregate invariant that has to be transactionally consistent that depends on 50 pieces of data.
– abuzittin gillifirca
Mar 26 at 12:45
DDD is a collection of design patterns and techniques that among other things prevent you ending up with 50 field monster classes. A domain model is not a lipstick you put on your pig of a database model. If you end up with a 50 field monster entity ask yourself what aggregate invariant that has to be transactionally consistent that depends on 50 pieces of data.
– abuzittin gillifirca
Mar 26 at 12:45
add a comment |
2 Answers
2
active
oldest
votes
SRP always applies. I would ask myself if that entity makes sense as a whole, or it would be easier to understand it and work with it if you are able find some internal substructure and split it that way.
If you have a 50-fields order, it might actually be a classical case where bounded contexts apply, that is where an order can be viewed differently by different subsystems, and only parts of the order are needed by each subsystems.
For "Domain Factory" the rule of thumb is that it contains anything related to the object creation.
For "Domain Service" it seems to be a stateless pile of logic that doesn't fit logically in entities. see this.
P.S. I don't think that a 1 MB class (10K lines of code or more) is ever acceptable by any software design methodology (unless it is generated code, and thus is not intended for humans). Unfortunately sometimes the code reaches that state accidentally, due to lack of design planning, fear of refactoring, or deliberate omission (a decision to postpone the tech debt). That depends on the app and programming languages, but my personal rule of thumb is to start worrying and improve the design if the class reaches 1K lines, or even a bit before that.
add a comment |
It is never acceptable to have an object that has 50 methods and using "rich" objects don't really lead to this. If you have that, you can use the standard methods of refactoring to solve the problem.
The SRP has many interpretations, but in one of these it means "things that change together should be together". I.e. it is "legal" to have cohesive things together in one class. Here are some more details on this: Single Responsibility Principle.
If you do "rich" modeling, i.e. object-orientation, then Services should not be used. Services are stateless scripts (i.e. procedures) that usually access data from other objects do something with it and put it back into other objects. Aside from conceptual/modeling problems, it leads to all sorts of practical problems too. Here is a presentation with a little more details: Object-Oriented Domain-Driven-Design.
Also, I went through Vaughn Vernon's repository looking for how/why Services are used and I found none with functionality that didn't have a better place in a real object.
Factories are a bit different, they are a purely technical thing to abstract construction and should contain only construction code.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346484%2fdo-rich-domain-models-mean-large-domain-classes-are-acceptable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
SRP always applies. I would ask myself if that entity makes sense as a whole, or it would be easier to understand it and work with it if you are able find some internal substructure and split it that way.
If you have a 50-fields order, it might actually be a classical case where bounded contexts apply, that is where an order can be viewed differently by different subsystems, and only parts of the order are needed by each subsystems.
For "Domain Factory" the rule of thumb is that it contains anything related to the object creation.
For "Domain Service" it seems to be a stateless pile of logic that doesn't fit logically in entities. see this.
P.S. I don't think that a 1 MB class (10K lines of code or more) is ever acceptable by any software design methodology (unless it is generated code, and thus is not intended for humans). Unfortunately sometimes the code reaches that state accidentally, due to lack of design planning, fear of refactoring, or deliberate omission (a decision to postpone the tech debt). That depends on the app and programming languages, but my personal rule of thumb is to start worrying and improve the design if the class reaches 1K lines, or even a bit before that.
add a comment |
SRP always applies. I would ask myself if that entity makes sense as a whole, or it would be easier to understand it and work with it if you are able find some internal substructure and split it that way.
If you have a 50-fields order, it might actually be a classical case where bounded contexts apply, that is where an order can be viewed differently by different subsystems, and only parts of the order are needed by each subsystems.
For "Domain Factory" the rule of thumb is that it contains anything related to the object creation.
For "Domain Service" it seems to be a stateless pile of logic that doesn't fit logically in entities. see this.
P.S. I don't think that a 1 MB class (10K lines of code or more) is ever acceptable by any software design methodology (unless it is generated code, and thus is not intended for humans). Unfortunately sometimes the code reaches that state accidentally, due to lack of design planning, fear of refactoring, or deliberate omission (a decision to postpone the tech debt). That depends on the app and programming languages, but my personal rule of thumb is to start worrying and improve the design if the class reaches 1K lines, or even a bit before that.
add a comment |
SRP always applies. I would ask myself if that entity makes sense as a whole, or it would be easier to understand it and work with it if you are able find some internal substructure and split it that way.
If you have a 50-fields order, it might actually be a classical case where bounded contexts apply, that is where an order can be viewed differently by different subsystems, and only parts of the order are needed by each subsystems.
For "Domain Factory" the rule of thumb is that it contains anything related to the object creation.
For "Domain Service" it seems to be a stateless pile of logic that doesn't fit logically in entities. see this.
P.S. I don't think that a 1 MB class (10K lines of code or more) is ever acceptable by any software design methodology (unless it is generated code, and thus is not intended for humans). Unfortunately sometimes the code reaches that state accidentally, due to lack of design planning, fear of refactoring, or deliberate omission (a decision to postpone the tech debt). That depends on the app and programming languages, but my personal rule of thumb is to start worrying and improve the design if the class reaches 1K lines, or even a bit before that.
SRP always applies. I would ask myself if that entity makes sense as a whole, or it would be easier to understand it and work with it if you are able find some internal substructure and split it that way.
If you have a 50-fields order, it might actually be a classical case where bounded contexts apply, that is where an order can be viewed differently by different subsystems, and only parts of the order are needed by each subsystems.
For "Domain Factory" the rule of thumb is that it contains anything related to the object creation.
For "Domain Service" it seems to be a stateless pile of logic that doesn't fit logically in entities. see this.
P.S. I don't think that a 1 MB class (10K lines of code or more) is ever acceptable by any software design methodology (unless it is generated code, and thus is not intended for humans). Unfortunately sometimes the code reaches that state accidentally, due to lack of design planning, fear of refactoring, or deliberate omission (a decision to postpone the tech debt). That depends on the app and programming languages, but my personal rule of thumb is to start worrying and improve the design if the class reaches 1K lines, or even a bit before that.
edited Mar 25 at 22:19
answered Mar 25 at 22:05
battlmonstrbattlmonstr
2,9021 gold badge12 silver badges24 bronze badges
2,9021 gold badge12 silver badges24 bronze badges
add a comment |
add a comment |
It is never acceptable to have an object that has 50 methods and using "rich" objects don't really lead to this. If you have that, you can use the standard methods of refactoring to solve the problem.
The SRP has many interpretations, but in one of these it means "things that change together should be together". I.e. it is "legal" to have cohesive things together in one class. Here are some more details on this: Single Responsibility Principle.
If you do "rich" modeling, i.e. object-orientation, then Services should not be used. Services are stateless scripts (i.e. procedures) that usually access data from other objects do something with it and put it back into other objects. Aside from conceptual/modeling problems, it leads to all sorts of practical problems too. Here is a presentation with a little more details: Object-Oriented Domain-Driven-Design.
Also, I went through Vaughn Vernon's repository looking for how/why Services are used and I found none with functionality that didn't have a better place in a real object.
Factories are a bit different, they are a purely technical thing to abstract construction and should contain only construction code.
add a comment |
It is never acceptable to have an object that has 50 methods and using "rich" objects don't really lead to this. If you have that, you can use the standard methods of refactoring to solve the problem.
The SRP has many interpretations, but in one of these it means "things that change together should be together". I.e. it is "legal" to have cohesive things together in one class. Here are some more details on this: Single Responsibility Principle.
If you do "rich" modeling, i.e. object-orientation, then Services should not be used. Services are stateless scripts (i.e. procedures) that usually access data from other objects do something with it and put it back into other objects. Aside from conceptual/modeling problems, it leads to all sorts of practical problems too. Here is a presentation with a little more details: Object-Oriented Domain-Driven-Design.
Also, I went through Vaughn Vernon's repository looking for how/why Services are used and I found none with functionality that didn't have a better place in a real object.
Factories are a bit different, they are a purely technical thing to abstract construction and should contain only construction code.
add a comment |
It is never acceptable to have an object that has 50 methods and using "rich" objects don't really lead to this. If you have that, you can use the standard methods of refactoring to solve the problem.
The SRP has many interpretations, but in one of these it means "things that change together should be together". I.e. it is "legal" to have cohesive things together in one class. Here are some more details on this: Single Responsibility Principle.
If you do "rich" modeling, i.e. object-orientation, then Services should not be used. Services are stateless scripts (i.e. procedures) that usually access data from other objects do something with it and put it back into other objects. Aside from conceptual/modeling problems, it leads to all sorts of practical problems too. Here is a presentation with a little more details: Object-Oriented Domain-Driven-Design.
Also, I went through Vaughn Vernon's repository looking for how/why Services are used and I found none with functionality that didn't have a better place in a real object.
Factories are a bit different, they are a purely technical thing to abstract construction and should contain only construction code.
It is never acceptable to have an object that has 50 methods and using "rich" objects don't really lead to this. If you have that, you can use the standard methods of refactoring to solve the problem.
The SRP has many interpretations, but in one of these it means "things that change together should be together". I.e. it is "legal" to have cohesive things together in one class. Here are some more details on this: Single Responsibility Principle.
If you do "rich" modeling, i.e. object-orientation, then Services should not be used. Services are stateless scripts (i.e. procedures) that usually access data from other objects do something with it and put it back into other objects. Aside from conceptual/modeling problems, it leads to all sorts of practical problems too. Here is a presentation with a little more details: Object-Oriented Domain-Driven-Design.
Also, I went through Vaughn Vernon's repository looking for how/why Services are used and I found none with functionality that didn't have a better place in a real object.
Factories are a bit different, they are a purely technical thing to abstract construction and should contain only construction code.
answered Mar 26 at 8:39
Robert BräutigamRobert Bräutigam
5,47410 silver badges29 bronze badges
5,47410 silver badges29 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346484%2fdo-rich-domain-models-mean-large-domain-classes-are-acceptable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stackoverflow.com/search?q=Rich+vs+Anemic+Domain+Model
– Hooman Bahreini
Mar 25 at 22:02
DDD is a collection of design patterns and techniques that among other things prevent you ending up with 50 field monster classes. A domain model is not a lipstick you put on your pig of a database model. If you end up with a 50 field monster entity ask yourself what aggregate invariant that has to be transactionally consistent that depends on 50 pieces of data.
– abuzittin gillifirca
Mar 26 at 12:45