Domain events are not described in the famous blue DDD book. When and how did they become part of the domain-driven design?
Eric Evans: What I've learned about DDD since the book
QCon 2009 Slides
2012 Video
Domain events express facts that happen in the domain and thus are first class citizens of the domain so there are very very important from the DDD point of view.
Even more, when interfacing with another bounded context, they could represent the contract between the two bounded contexts.
P.S. they are covered by the "red DDD book" in chapter 8.
Related
Consider certain kinds of objects involved Domain-Driven Design (DDD): Entities, Value Objects, Domain Events, and Domain Services.
Which of these are considered to be Domain Objects? And are there other names for abstractions that encapsulate a subset of those?
I can identify various abstractions that are useful to have when talking about DDD or domain models:
Entities and Value Objects. I often find myself mentioning "Entities or Value Objects". Most notably, these are the ones that model the domain's state. In contrast, Domain Services are stateless, and I would argue that Domain Events merely reflect information about how the domain came to be in its current state.
Entities, Value Objects, and Domain Events. These may all contain or represent data, whereas the Domain Services only define behavior.
All objects recognized by the domain model. It is useful to be able to talk about parts of the domain model in general, as opposed to concepts outside of it.
It's interesting how even Stack Overflow's domain-object tag has a confusing definition:
Domain Objects are objects made for dealing with the domain logic at the Model layer. These objects generally simulate real (or virtual) items from real-life: Person, Post, Document, etc.
The initial definition, focused on "dealing with the domain logic", leans towards "all objects recognized by the domain model". The examples then lean towards "Entities and Value Objects".
DDD hammers on a clearly defined, unambiguous Ubiquitous Language, and with good reason. Shouldn't it lead by example? :)
Which of these are considered to be Domain Objects?
All of them. They are "objects" that implement our domain model. In the original DDD text, Eric Evans also used the phrase "model elements".
The distinctions between them are largely a consequence of the constraints of the Java language. You wouldn't need "value objects" if you could just create bespoke values; you wouldn't need "domain services" if you could just pass around the capabilities you need. You wouldn't need "domain events" if you have "messaging" as a ubiquitous construct, and so on.
DDD hammers on a clearly defined, unambiguous Ubiquitous Language, and with good reason. Shouldn't it lead by example? :)
Well, part of the riddle is that these patterns are part of a general purpose language, and one of the central messages of DDD is that you shouldn't allow general purpose concerns to distract you from the domain itself.
That said... yeah - it would be better today if Evans had a rich understanding of these ideas eighteen years ago, and was able to introduce the best language and provide counter measures to prevent semantic diffusion.
I attended a Webinar today by someone quite famous and respected author, lecturer, and expert in software engineering, architecture, and design. The webinar topic was "Incremental Architecture". This luminary stated that the concept of an entity in DDD has nothing to do with the concept of entity in databases. It was an unfortunate choice of term by Eric Evans in his original 2003 book. I was not satisfied with his explanation, and I find that his statement to potentially be very confusing to anyone trying to use DDD in design.
My question: what exactly does the term entity in DDD mean? - if it is not the very well understood and very well defined concept of entity in databases, ORM frameworks, JPA, development frameworks (Spring), etc.
Extensive research in software architecture.
This is a question about DDD strategic design. Coding is not involved.
Not relevant to my question. You allow a topic tag about DDD, which is a design approach, not a coding approach, yet you insist on having code-related questions. How is DDD related to coding?
My question: what exactly does the term entity in DDD mean?
Evan's defined entity in Chapter 5 (A Model Expressed in Software) of Domain Driven Design.
Entities (a.k.a. Reference Objects) ... are not fundamentally defined by their properties, but rather by a thread of continuity and identity.
An object defined primarily by its identity is called an ENTITY.
An ENTITY is anything that has continuity through a life cycle and distinctions independent of attributes that are important to the application's user.
It is an in memory abstraction of something that changes over time. It's a temporally varying membership function which for time t maps an identifier to some state. It's used within the domain model to represent things that change.
An example of a entity in a domain model might be... a question on stack overflow.
The meaning of "entity" in Domain-Driven Design
When somebody edits the text, or changes the title, or downvotes... it's still the same question, in that there's a progression from what the text used to be to what the text is now. It changes over time from having this text to having that text.
A simple entity in a domain model might map to a single row in a relational database, but it won't necessarily do so. More precisely, we might save the current state of the entity in a single row. But if that state includes a collection, then it is likely that the state will be distributed across multiple rows, perhaps in multiple tables.
You allow a topic tag about DDD, which is a design approach, not a coding approach, yet you insist on having code-related questions. How is DDD related to coding?
If The Source Code is The Design, then the design necessarily includes coding. The middle section of the Domain Driven Design book, which gets most of the attention, covers topics in modeling domains in code.
Truth be told: domain-driven-design turns up fewer questions with authoritative answers than, for example java.
An entity is a type that has an identity. The id could be anything but it has to be unique to the system and in fact depending on the subdomain you are in, the identity/entity might change.
For example:
A database might have a "User" Table that has fields "firstname", "lastname" e.t.c.
In DDD for an ecommerce application's purchase subdomain, you might have "Shoppers". These Shoppers might have an id of "firstname lastname". In the "Shipping" subdomain of the same application, you'll also have the concept of a "Shopper"(or buyer) but this time the identity of the shopper might be "Full address".
So, where a database entity is nothing more than a grouping of data with an identifier, A DDD entity is a concept. The concept is pertinent to the system, described in the ubiquitous language and is the central actor around which many functions in the domain will operate. The data that populates a DDD's entity usually comes from several datatable entities.
Im new to learn DDD concept and i cant understand something.
1-What difference between Context Map and Bounded Context and SubDomain?
2-How to recognize relation between Bounded Context ?
As said in the comment, this is a wide subject, and very important in DDD. It is the strategic part of DDD. Anyway I will try to answer your questions with an overall explanation:
DDD is about understanding and distilling the domain of the problem we want to solve. It is a continuous process of learning about the domain, talking to the domain experts. All people (developers, business people, etc) speak the same language. This language is used everywhere (conversations, documentation, source code, ...). It is called the Ubiquitous Language (UL).
The problem domain may have different areas of functionality, which would be domains too. They are the subdomains. So a subdomain is a subset of the problem domain. It is like splitting the problem into smaller subproblems, and a subdomain would be the domain of a subproblem. There are 3 kinds of subdomains:
Core: The point of distillation is to discover the subdomain that has value for the business, i.e., the one that will make your product better than others of the same kind. Such subdomain is the "core subdomain". For example, in "project management", the "task assignement" would be core.
Supporting: It is specialized in some business aspect that helps the core functionality. For example, in "project management", a "calendar" (for marking tasks delivery dates).
Generic: Functionality that maybe needed by any kind of application. For example, authentication and authorization of users.
Subdomains belong to the problem space.
To solve the problem, you model the subdomains, and you create bounded contexts (BCs). In practice, a BC is an autonomous application that contains the software model of a subdomain. A BC has its own UL. It is the context on which a term of the UL has a meaning. UL and BCs are the most important things in DDD. UL drives the BCs identification.
Ideally, you should align 1:1 the subdomains of the problem space with the BCs of the solution space, i.e., you should have a BC for each subdomain.
A team can develop one or more BCs, but a BC should be developed by just one team.
BCs belong to the solution space.
Context Map: It is a drawing that shows the BCs, and the relationships among them. Every relationship is classified in one of the following patterns:
Partnership
Shared Kernel
Customer-Supplier
Conformist
Anticorruption Layer
Open Host Service
Published Language
Separate Ways
Big Ball of Mud
Recognizing which pattern to apply in a relationship it will depend on the particular case you have. Some things that you have to consider are:
The 2 teams collaborate together.
One of the teams doesn't care about the other one.
The teams can negotiate.
The teams are independent.
Changes on a model (upstream) affects to the other model (downstream).
As #Augusto mentioned, this is a couple of chapters in the blue book, but here goes.
The domain model is found in the business rules and how people talk but a simplification of it is captured in code. Certain naming is consistent and the necessary invariants are enforced in the model.
A bounded context is mostly conceptual (might be a namespace, module, project in code as well...). It is the intention to keep a domain model consistent within it. So within the context, a certain ubiquitous language is used. And a model need only serve the needs of THAT context. It is the boundary in which the model can be used. In terms of recognizing these relationships? Some might be subtle but most are not. At least some people in the team will want to "avoid duplication" by unifying the model... so that is a clear indication that there is a relationship. Names are often the same or similar... or could be the same but one is better suited to one domain and another to another domain.
A context map is a bit more of a project management tool. It is a map of how different contexts (and the models within) relate to each other. In an Ordering Domain in an e-commerce system you may have a product. It would lead to A LOT of complication trying to have a unified Product in a model that spanned Ordering, Payments, Content for the website and Inventory domains (for example). So each of those domains should have a separate model. The context map is a diagram and related documentation that relates these bounded contexts together since there would be relationships and translation of data across from one model to the next, as an order flows through the system.
The last element you asked about is a subdomain. Here you probably are referring to a generic subdomain. Personally, I think the name is a little confusing. It makes it seem like a subset of the model. Maybe this is on purpose but I generally think of them as their own domain, just one that is not central to the business's proposition. For instance, if the aforementioned e-commerce company was known for its same day or next day delivery, then they probably shouldn't buy an off-the-shelf solution to inventory and shipping management. On the other hand, if they were focusing on a market that just wanted the cheapest deal but didn't mind waiting a few days, then that would be a perfect candidate for a generic subdomain.
My DDD glossary which has plenty of links at the bottom to more detailed articles.
If you are serious about learning this subject and can get your hands on some books:
Domain-driven Design by Eric Evans
Implementing Domain-driven Design by Vaughn Vernon
Domain-driven Design made functional by Scott Wlaschin (my favourite)
One key concept in Domain-Driven Design (DDD) is the ubiquitous language.
What is the typical scope (consistency border) of such a ubiquitous language? Is it scoped by the bounded context (e.g. a system/component in a certain domain) or by the domain itself? In bigger enterprises, different systems (i.e. bounded contexts) might implement the same domain.
My assumption is that it's bound to a bounded context as consistency cannot be guaranteed across multiple bounded context (even if they belong to the same domain) but I am not sure.
Bounded Context is where Ubiquitous Language lives.
Vaughn Vernon defines DDD in short as:
Developing Ubiquitous Language within Bounded Context
This question has been asked and answered before
UPDATE: I gave a talk at DDD Norway meetup about, covering the importance of UL and contexts. Slides can be found here.
The ubiquitous language is defined within a bounded context. This becomes obvious when you look at different BCs that contain the same term. The concept of a book in an online shop is completely different than a book in a authoring system.
From Implementing DDD by Vaughn Vernon:
Bounded Context Is Explicit and Linguistic
A Bounded Context is an explicit boundary within which a domain model exists. Inside the boundary all terms and phrases of the Ubiquitous Language have specific meaning, and the model reflects the Language with exactness.
+1 for BC. Here's a quote from
Patterns, Principles, and Practices of Domain-Driven Design by Scott Millett and Nick Tune:
In Chapter 4, “Model-Driven Design,” you are introduced to the concept of the ubiquitous language (UL) and the importance of models defined in a context that are free from linguistic ambiguity. The context refers to the specific responsibility of the model, which helps to decompose and organize the problem space. A bounded context takes the idea of a model in context further by encapsulating it within a boundary of responsibility. This boundary is a concrete technical implementation, as opposed to the context that is more abstract. The bounded context enforces communication in such a manner as to not lessen the purity of the model.
A bounded context is first and foremost a linguistic boundary. [...]
Speak a ubiquitous language within an explicitly bounded context.
At Explore DDD 2018 (Denver), Eric Evans put up a slide that said:
DDD is a set of guiding principles:
Focus on the core domain
Explore models in a creative collaboration of domain practitioners and software practitioners
Speak a ubiquitous language within an explicitly bounded context
This is not only an extremely succinct summary of DDD by its founder but the 3rd principle clearly explains the linkage between "ubiquitous language" and "bounded context". Note he says "a" ubiquitous language, not "the". There can be more than one, but each is within a different bounded context.
I'm analyzing a fairly enterprise resource planning software and because an ERP covers many areas from accounting to sales and CRM I have chosen to use Domain Driven Design. Now I have two questions :
What are main APPLIED (not in theory) resources to start DDD?
How can I find out for example to which Domain or Module an "Invoice"
belongs ? Does it belongs to "Accounting" or "Sales"?
There may be many examples of such situation where I get confuse when separating Entities and Domains...
How can I overcome this problem ?
I'm not a DDD authority in any way, but here's my 2 cents
1) Have you read the blue bible? The examples there are taken from Eric Evans experience building a real shipping platform. I haven't seen any other published example as big as the one in the book.
2) Invoice can belong to both, but it will probably mean different things on each domain, in sales it will be linked to an order, payment and so on; in Accounting it will be linked to a Ledger and an Account.
You won't find a unique domain to solve the whole ERP problem. I'm not experienced with ERPs, but knowing sales and CRM, I would say that you might find 15+ different domains, some will be tiny frameworks, some will be solve chunky parts of the problem.
About your confusion: What I've done in the past is to find questions related to DDD here in SO (some are really enlightening) and read blogposts from people who know quite a lot about DDD - lostechies have quite a few good blogposts about DDD.
There is two resources i would recommend that use DDD in practice: the first one is the one and only famous book Applying Domain-Driven Design and Patterns_ With Examples in C# and .NET.pdf, and the other one is dotNET Domain Driven Design with C# - Problem - Design - Solution.pdf but they both assume you have read Eric Evan's book first.
i don't think anyone is qualified to answer the second question very well, and most people will say it depends on context and you particular application. the hard truth is that DDD is about design and it requires sophisticated skills (it is not easy). so i will suggest you develop your code incrementally with backing tests so you could change you design when the right moment comes (that what eric refers to as a Breakthrough).