What are the criteria for labeling a domain model as anemic? - domain-driven-design

So far, I have not come across a blog post or an article which describes the objective criteria for tagging a domain model as anemic. I think, it would definitely help to set objective criteria for anemic domain models.
Few years back, I designed a domain model. I had few tables in database (around 7). I created exactly same number of classes in code. I implemented repository pattern for each of those classes. Today, I definitely feel that it was anemic domain model. There was a chance for me to design an object oriented domain model, but the domain model that I designed was relational in nature. From that experience, one criteria that I have defined is - if the object model maps one - to - one with you relational model, then it could be a sign for anemic domain model.
Are there any other criteria that might be pointing to anemic domain model?
Thanks.

The article you're looking for is by Martin Fowler and is available at:http://martinfowler.com/bliki/AnemicDomainModel.html .
The fundamental criteria is basically an object model that exposes the semantics of the business domain, but fails to encapsulate the business logic, which includes behavior and invariant constraints.

Related

Domain model and EF Core model

When looking at the post "Should Entities in Domain Driven Design and Entity Framework be the same?" the accepted answer states that domain entities and EF Entities can only be the same when using code first. This so that the entities can remain "pure".
However, because of this inpediment: "Discussion on many-to-Many relationships (without CLR class for join table)" it is not possible to create an order entity with a collection of product entities without specifying a special entity for the association table (orderline entity).
I now see colleagues taking these association tables into their domain entities and i feel that is wrong because it hints towards coping with persistence and not towards being true to the domain. They are not "pure" anymore in my opinion.
Would you say that it is impossible to have the same Domain entities in EF Core because of the association table entities? How can i cope with this in EF Core?
But in a regular/classic Ordering domain there is a need for an orderline (or order-line-item or whatever you want to call it) because you need to store the quantity and the item price along the product ID.
In most DDD examples this item is a Value object from the DDD point of view and an Entity from the Persistence point of view. If you are wondering how a Value object could be an ORM Entity you should read Persisting Value Objects from the book Implementing Domain Driven Design by Vaughn Vernon.
There are, however cases when the Domain model does not fit 100% percent with the Persistence model. In such cases one needs to attach some meta information to the Domain models in order to match the Persistence models. In general you have two options:
you can add the metadata to some external files, like XML-files;
it has the advantage that it keeps the Domain model agnostic in regard to the persistence but
it has the disadvantage that one must remember to change the external files when the Domain model changes
you can annotate the Domain models
it has the advantage that it is easy to change at the same time the Domain model and the Persistence model by having the information in the same file; it follows the principle: "things that change together stay together" (Common Closure Principle)
it has the disadvantage that it pollutes the Domain model with Infrastructure concerns
If I have to choose, I tend to choose to annotate the Domain models, but you should make that decision by yourself.

In Domain Driven Design (DDD) How do you record and document a model

In Domain Driven Design how do you document key aspects of your model so that it can be communicated with your team and so that it can be developed over time?
By Key Aspects I mean:
ubiquitous language
aggregate roots
Entities / Value Object
Invariants
In the code. And in conversations. And on whiteboards, and documents, and models...
The key points are (1) ubiquity and (2) consistency. So if a domain expert talks about "Assessing a Loan Application", you should have code that syntactically and semantically matches that concept. So you might have LoanApplication.Assess(). You wouldn't have ApplicationManager.QualifyApplication() or similar.
So you would minimally record the language in the code. You may also choose to record in documentation and/or diagrams. You will also use on whiteboards and in discussions. But in all cases it's the same language.
hth.

UML Domain Modeling

What is the difference between a domain model and a data model?
A datamodel is a design model that only describes data and it's relations. The model contains entities, but they are described in terms of what data they own not how they act on this data or what their responsibilities are.
An domain model on the other hand, is a conceptual model used in analysis of a problem domain. It describes the domain in terms of entities that have relations, data and behaviour. It describes the responsibilities of those entities as relevant for understanding the problem domain.
BTW an excelent and very short introduction to UML is:
UML Distilled: A Brief Guide to the Standard Object Modeling Language
A data model is focused on the DB schema definition, including tables, columns, and relationships.
A domain model is focused on the business domain, including concepts (classes of objects), behavior (methods/logic), and relationships.
In both cases, the cardinality is used for relationships (e.g. 1:1, 1:Many, 0:Many, ...).
That said, you would ideally like the data model and domain model to be closely related, i.e. a Person with name, ... and a MailingAddress, ... relates to a PERSON table with a NAME column and a FK to a MAILING_ADDR table entry. You have to decide where logic is hosted - in the objects in the software system vs. in the DB via procedures, triggers, and such.
I think it's important to provide some clarity here for posterity.
A data model is a design for how to structure and represent information. By structure, I mean concerns like "fifth normal form". By representation, I mean choosing a computer serialization, such as integer, floating point, or string.
The term domain model actually has two conflated meanings.
A model of essential characteristics of real or imaginary things in the world. In this kind of model, classes represent human conceptualizations and instances are things in the world. For example, a "Person" class would have instances including you and me, and an essential characteristic might be that every Person has a mother. This kind of model is often called an conceptual ontology or concept model and is intended to provide meaning.
A model of required information about things in the world, usually with some system in mind. In this kind of model, classes represent information that must be stored about things in the world. For example, a "Person" class would have instances representing required information about you and me, such as first name, last name, date of birth, current height, and current weight. This information often does not include all essential characteristics, such as our mothers, because, for the purposes of a particular system, that information is not required. This kind of model is often called an information model, conceptual data model, or operational ontology.
Both the UML and OWL languages can be used to represent either kind of domain model. Both can be considered analysis models, as they are used to analyze a domain. One is used to understand things in a domain, the other is used to gather requirements to build a particular software or database system for things in a domain. Both are necessary, and, unfortunately, they are usually conflated such that people building an analysis model are themselves confused about what they are modeling!
I think that domain model and data model are now pretty much the same with new top down modelling technologies. I mean that you can model in a class diagram and only add database stereotypes in your diagram. If you use the tool that I use then your ejb3 annotation would be immediately synchronized with your code. The next step is only to use a mapper to create your database. This technology only works with Java

Domain Modeling, Domain Objects in DDD

I'm really new to DDD and trying to grasp some of the concepts.
Could someone explain me the idea behind Domain Modeling in DDD.
I have already gone through wikipedia explanation: http://en.wikipedia.org/wiki/Domain_model but still seems like there are some gray areas in my understanding.
Based on what I understood, domain modeling involves building a model around the business entities to express their relationships, express the entities that participate in the model etc..
Isn't this something that has been in practice always? in Object Oriented world, you model business entities into classes, objects etc.. and build the software around this.
What I do not understand is the emphasis Domain Modeling gets in DDD. Is it the same object/class modeling that you find in OO world, or is this something new to DDD ?
How does it differ from Object Oriented design/modeling?
Your answers are highly appreciated.
One distinction is that a "proper" implementation of the Domain Model Pattern in DDD is isolated from cross-cutting concerns.
For example, it contains nothing to do with databases or other persistence. Where it contains validation logic, it is business validation, not "does the name exceed the column length?" validation.
The idea is that the domain model encapsulates "the business" -- in business terms ("ubiquitous language"), to the extent possible -- and exposes relevant aspects of the business to "the program" without acquiescing to the needs of the software.
On the flip side, "the software" is concerned with IO, UI, and the like, but delegates all business logic to the domain model.
In principle, you can wrap your domain model up in an assembly and use it across multiple applications. When business rules change, as they do, you have one very logical place in which to affect the changes (because the model is a 1:1 or nearly-so representation of the relevant aspects of the business and is described in the same terms as the business).
The Domain in DDD does not need to be implemented in OO. In my experience an OO domain model is usually best, but there are very valid examples of situations in which it may not be.
You might implement a domain in rules, with a rule engine (example in The Netherlands where this is done for a large mortgage application). Or you might do it in a functional language. The essence is that your domain, in however fashion it is implemented, is isolated from what I usually call the technical aspects of your application (or, as the previous answer calls it, cross-cutting concerns, although I think there may very well be cross-cutting concerns within a domain). An isolating layer, which may be implemented using adapters, makes the domain as much as possible, even completely, independent from the technicalities. This layer usually leverages patterns such as Facade and Observer.

What's the difference between Data Modelling and Domain Modelling?

By the way - with reference to data modelling I'm referring to logical or conceptual data models - not physical ones.
The question came up during a discussion at work; naturally I leapt to Wikipedia to get some basic definitions in place - hoping that they might clarify the difference - but they didn't...
A conceptual schema or conceptual data model is a map of concepts and their
relationships.
Logical Data Modles seem very similar (from this definition):
A logical data model (LDM) in systems
engineering is a representation of an
organization's data, organized in
terms entities and relationships and
is independent of any particular data
management technology.
Where-as...
A domain model, or Domain Object Model
(DOM) in problem solving and software
engineering can be thought of as a
conceptual model of a system which
describes the various entities
involved in that system and their
relationships.
The differences between domain model vs conceptual data model seems particularly murky.
One of the things which adds to this confusion is that (from what I've seen) a domain model is usually modelled using a UML class diagram - the class entity in a UML class diagram supports methods - our colleague maintains that a domain model must not contain "operations". I can understand domain modellers using a sub-set of a UML class diagram - but isn't it dangerous to assume people will refrain from including "operations" if the tooling they are using supports it?
Good question, the problem is that it depends on the definion of the terms, I think they differ slightly based on the sources.
I would agree with previous answer - domain models are for describing the problem domain, at least the part you need to develop a solution. You describe all the various entities, their relations and their behaviour. I think that this is also the view from the Domain Driven design perspective.
Data models on the other hand are used for describing the data in your system and relations or associations between them. This is useful for describing what needs to be stored in the system and might also give hints how. I think data models would apply for your "no operations" rule, because they are not important in this respect.
Domain Modeling (in the sense of Domain Driven Design) is all about modelling the behavior of the domain concepts, while Data Modeling focuses mainly on... data.
It doesn't mean that Domain Modeling ignores data structures. It just puts more emphasis on operations and how they can be uses to solve problems.
I don't know much about other than Domain Driven Design domain modelling techniques, but DDD involves (apart from modeling data and behavior) also explicit modelling of consistency boundaries (aggregates).
This is an old thread, but here's a slightly improved answer to clarify some of the others posted here.
The concept of 'domain' (and other kinds of models such as conceptual, logical and physical) is orthogonal to the technique used to represent the model (eg. ERD, UML etc). A domain model is essentially the same as a conceptual model, but different design methodologies might have slightly different terms and definitions. While it's common to draw domain models using UML or ERD to describe entities and their relationships (or classes/methods in UML), this only applies to modelling the information to be managed by a system - logically, the concept of domain modelling (or conceptual modelling, logical modelling or physical modelling, etc) can apply to any problem situation and a solution. Depending on the nature of the problem and the problem solving approach, other modelling techniques could be used to achieve the same goal.
In short, domain modelling and conceptual modelling are essentially the same thing, hair-splitting definitions aside. The concept applies to what the modeller is trying to communicate. The concept of data modelling (ie. ERD) or object-oriented modelling (ie. UML) refers to how the modeller communicates it.
I would say that a domain model describes the problems (what we want to manage/solve) on a given domain. The data model would describe the solution (how we're going to solve it) to the problem described on the domain model.
However, we are indeed in murky waters...

Resources