Domain Object
   HOME

TheInfoList



OR:

Domain-driven design (DDD) is a major
software design Software design is the process by which an agent creates a specification of a software artifact intended to accomplish goals, using a set of primitive components and subject to constraints. Software design may refer to either "all the activity ...
approach, focusing on modeling software to match a
domain Domain may refer to: Mathematics *Domain of a function, the set of input values for which the (total) function is defined **Domain of definition of a partial function **Natural domain of a partial function **Domain of holomorphy of a function * Do ...
according to input from that domain's experts. Under domain-driven design, the structure and language of software code (class names,
class method A method in object-oriented programming (OOP) is a procedure associated with a message and an object. An object consists of ''state data'' and ''behavior''; these compose an ''interface'', which specifies how the object may be utilized by any of ...
s,
class variable In class-based, object-oriented programming, a class variable is a variable defined in a class of which a single copy exists, regardless of how many instances of the class exist. A class variable is not an instance variable. It is a special typ ...
s) should match the business domain. For example, if software processes loan applications, it might have classes like loan application, customer, and methods such as accept offer and withdraw. Domain-driven design is predicated on the following goals: * placing the project's primary focus on the core
domain Domain may refer to: Mathematics *Domain of a function, the set of input values for which the (total) function is defined **Domain of definition of a partial function **Natural domain of a partial function **Domain of holomorphy of a function * Do ...
and domain logic; * basing complex designs on a model of the domain; * initiating a creative collaboration between technical and
domain expert A subject-matter expert (SME) is a person who has accumulated great knowledge in a particular field or topic and this level of knowledge is demonstrated by the person's degree, licensure, and/or through years of professional experience with the s ...
s to iteratively refine a conceptual model that addresses particular domain problems. Criticisms of domain-driven design argue that developers must typically implement a great deal of isolation and encapsulation to maintain the model as a pure and helpful construct. While domain-driven design provides benefits such as maintainability, Microsoft recommends it only for complex domains where the model provides clear benefits in formulating a common understanding of the domain. The term was coined by Eric Evans in his book of the same title published in 2003.


Overview

Domain-driven design articulates a number of high-level concepts and practices. Of primary importance is a ''domain'', the subject area to which the user applies a program is the domain of the software. A software's domain governs its ''context'', the setting in which a word or statement appears that determines its meaning. From this, developers build a ''domain model'': a system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain. These aspects of domain-driven design aim to foster a ''common language'' shared by domain experts, users, and developers—the ''ubiquitous language''. The ubiquitous language is used in the domain model and for describing system requirements. Ubiquitous language is one of the pillars of DDD together with ''strategic design'' and ''tactical design''. In domain-driven design, the
domain layer In computer software, business logic or domain logic is the part of the program that encodes the real-world business rules that determine how data can be Create, read, update and delete, created, stored, and changed. It is contrasted with the remai ...
is one of the common layers in an
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pro ...
multilayered architecture In software engineering, multitier architecture (often referred to as ''n''-tier architecture) is a client–server architecture in which presentation, application processing and data management functions are physically separated. The most wide ...
.


Kinds of models

Domain-driven design recognizes multiple kinds of models. For example, an ''entity'' is an object defined not by its attributes, but its
identity Identity may refer to: * Identity document * Identity (philosophy) * Identity (social science) * Identity (mathematics) Arts and entertainment Film and television * ''Identity'' (1987 film), an Iranian film * ''Identity'' (2003 film), ...
. As an example, most airlines assign a unique number to seats on every flight: this is the seat's identity. In contrast, a ''
value object In computer science, a value object is a small object that represents a ''simple'' entity whose equality is not based on identity: i.e. two value objects are ''equal'' when they ''have'' the same ''value'', not necessarily being the ''same object''. ...
'' is an immutable object that contains attributes but has no conceptual identity. When people exchange business cards, for instance, they only care about the information on the card (its attributes) rather than trying to distinguish between each unique card. Models can also define ''events'' (something that happened in the past). A domain event is an event that domain experts care about. Models can be bound together by a root entity to become an ''aggregate''. Objects outside the aggregate are allowed to hold references to the root but not to any other object of the aggregate. The aggregate root checks the consistency of changes in the aggregate. Drivers do not have to individually control each wheel of a car, for instance: they simply drive the car. In this context, a car is an aggregate of several other objects (the engine, the brakes, the headlights, etc.)


Working with models

In domain-driven design, an object's creation is often separated from the object itself. A ''repository'', for instance, is an object with methods for retrieving domain objects from a data store (e.g. a database). Similarly, a
factory A factory, manufacturing plant or a production plant is an industrial facility, often a complex consisting of several buildings filled with machinery, where workers manufacture items or operate machines which process each item into another. T ...
is an object with methods for directly creating domain objects. When part of a program's functionality does not conceptually belong to any object, it is typically expressed as a service.


Relationship to other ideas

Although domain-driven design is not inherently tied to object-oriented approaches, in practice, it exploits the advantages of such techniques. These include entities/aggregate roots as receivers of commands/method invocations, the encapsulation of state within foremost aggregate roots, and on a higher architectural level, bounded contexts. As a result, domain-driven design is often associated with Plain Old Java Objects and Plain Old CLR Objects. While technically technical implementation details, specific to
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
and the
.NET Framework The .NET Framework (pronounced as "''dot net"'') is a proprietary software framework developed by Microsoft that runs primarily on Microsoft Windows. It was the predominant implementation of the Common Language Infrastructure (CLI) until bein ...
respectively, these terms reflect a growing view that domain objects should be defined purely by the business behavior of the domain, rather than by a more specific technology framework. Similarly, the
naked objects Naked objects is an architectural pattern used in software engineering. It is defined by three principles: The naked object pattern's innovative feature arises by combining the and principles into a principle: The naked objects pattern was ...
pattern holds that the user interface can simply be a reflection of a good enough domain model. Requiring the user interface to be a direct reflection of the domain model will force the design of a better domain model.. Domain-driven design has influenced other approaches to software development. Domain-specific modeling, for instance, is domain-driven design applied with
domain-specific language A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging f ...
s. Domain-driven design does not specifically require the use of a
domain-specific language A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging f ...
, though it could be used to help define a domain-specific language and support
domain-specific multimodeling Domain-specific multimodeling is a software development paradigm where each view is made explicit as a separate domain-specific language (DSL). Successful development of a modern enterprise system requires the convergence of multiple views. Bus ...
. In turn,
aspect-oriented programming In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding behavior to existing code (an advice) ''without'' modifying t ...
makes it easy to factor out technical concerns (such as security, transaction management, logging) from a domain model, letting them focus purely on the business logic.


Model-driven engineering and architecture

While domain-driven design is compatible with model-driven
engineering Engineering is the use of scientific method, scientific principles to design and build machines, structures, and other items, including bridges, tunnels, roads, vehicles, and buildings. The discipline of engineering encompasses a broad rang ...
and
architecture Architecture is the art and technique of designing and building, as distinguished from the skills associated with construction. It is both the process and the product of sketching, conceiving, planning, designing, and constructing building ...
, the intent behind the two concepts is different. Model-driven architecture is more concerned with translating a model into code for different technology platforms than defining better domain models. However, the techniques provided by model-driven engineering (to model domains, to create domain-specific languages to facilitate the communication between domain experts and developers,...) facilitate domain-driven design in practice and help practitioners get more out of their models. Thanks to model-driven engineering's model transformation and code generation techniques, the domain model can be used to generate the actual software system that will manage it.


Command Query Responsibility Segregation

Command Query Responsibility Segregation In information technology, Command Query Responsibility Segregation (CQRS) is a system architecture that extends the idea behind command–query separation Command-query separation (CQS) is a principle of imperative computer programming. It was d ...
(CQRS) is an architectural pattern for separating reading data (a 'query') from writing to data (a 'command'). CQRS derives from Command and Query Separation (CQS), coined by
Greg Young Greg Young may refer to: * Greg Young (footballer) (born 1983), English footballer * Greg Young (basketball), American basketball coach * Greg Young (planner), Australian urban planner {{hndis, Young, Greg ...
. Commands mutate state and are approximately equivalent to method invocation on aggregate roots or entities. Queries read state but do not mutate it. While CQRS does not require domain-driven design, it makes the distinction between commands and queries explicit with the concept of an aggregate root. The idea is that a given aggregate root has a method that corresponds to a command and a command handler invokes the method on the aggregate root. The aggregate root is responsible for performing the logic of the operation and yielding either a number of events, a failure response or just mutating its own state that can be written to a data store. The command handler pulls in infrastructure concerns related to saving the aggregate root's state and creating needed contexts (e.g., transactions).


Event sourcing

Event sourcing is an architectural pattern in which entities do not track their internal state by means of direct serialization or object-relational mapping, but by reading and committing events to an
event store {{more citations needed, date=September 2015 An event store is a type of database optimized for storage of events. Conceptually, in an event store, only the ''events'' of a dossier or policy are stored. The idea behind it is that the dossier or ...
. When event sourcing is combined with CQRS and domain-driven design, aggregate roots are responsible for validating and applying commands (often by having their instance methods invoked from a Command Handler), and then publishing events. This is also the foundation upon which the aggregate roots base their logic for dealing with method invocations. Hence, the input is a command and the output is one or many events which are saved to an event store, and then often published on a message broker for those interested (such as an application's view). Modeling aggregate roots to output events can isolate internal state even further than when projecting read-data from entities, as in standard ''n''-tier data-passing architectures. One significant benefit is that axiomatic theorem provers (e.g. Microsoft Contracts and CHESSa MS bug finding tool
/ref>) are easier to apply, as the aggregate root comprehensively hides its internal state. Events are often persisted based on the version of the aggregate root instance, which yields a domain model that synchronizes in distributed systems through optimistic concurrency.


Notable tools

Although domain-driven design does not depend on any particular tool or framework, notable examples include: *
Actifsource Actifsource is a domain specific modeling workbench. It is realized as plug-in for the software development environment Eclipse. Actifsource supports the creation of multiple domain models which can be linked together. It comes with a UML-like g ...
, a plug-in for
Eclipse An eclipse is an astronomical event that occurs when an astronomical object or spacecraft is temporarily obscured, by passing into the shadow of another body or by having another body pass between it and the viewer. This alignment of three ce ...
which enables software development combining DDD with
model-driven engineering Model-driven engineering (MDE) is a software development methodology that focuses on creating and exploiting domain models, which are conceptual models of all the topics related to a specific problem. Hence, it highlights and aims at abstract re ...
and code generation. *
CubicWeb CubicWeb is a free and open-source semantic web application framework, licensed under the LGPL. It is written in Python. It has been an open free software project since October 2008, but the project began in 2000 and was initially developed by L ...
, an open source semantic web framework entirely driven by a data model. High-level directives allow to refine the data model iteratively, release after release. Defining the data model is enough to get a functioning web application. Further work is required to define how the data is displayed when the default views are not sufficient. *
OpenMDX OpenMDX is an open-source model-driven architecture (MDA) software platform, a framework suited for domain-driven design (DDD). It is based on the Object Management Group's MDA standards. OpenMDX supports Java SE, Java EE, and .NET runtime enviro ...
, an open-source, Java-based, MDA Framework supporting
Java SE Java Platform, Standard Edition (Java SE) is a computing platform for development and deployment of portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE). The platform uses Ja ...
,
Java EE Jakarta EE, formerly Java Platform, Enterprise Edition (Java EE) and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE with specifications for enterprise features such as distributed computing and web serv ...
, and .NET. OpenMDX differs from typical MDA frameworks in that ''"use models to directly drive the runtime behavior of operational systems"''. *
Restful Objects Restful Objects is a standard covering RESTful interfaces to domain object models. The specification is published under a Creative Commons license. Representations and resources defined by the standard The standard defines a small set of JSON re ...
, a standard for mapping a Restful API onto a domain object model (where the domain objects may represent entities, view models, or services). Two open source frameworks (one for Java, one for .NET) can create a Restful Objects API from a domain model automatically, using reflection.


See also

* Data mesh, a domain-oriented data architecture * Event storming *
Knowledge representation Knowledge representation and reasoning (KRR, KR&R, KR²) is the field of artificial intelligence (AI) dedicated to representing information about the world in a form that a computer system can use to solve complex tasks such as diagnosing a medic ...
*
Ontology (information science) In computer science and information science, an ontology encompasses a representation, formal naming, and definition of the categories, properties, and relations between the concepts, data, and entities that substantiate one, many, or all domains ...
* Semantic analysis (knowledge representation) *
Semantic networks A semantic network, or frame network is a knowledge base that represents semantic relations between concepts in a network. This is often used as a form of knowledge representation. It is a directed or undirected graph consisting of vertices, ...
*
Semantics Semantics (from grc, σημαντικός ''sēmantikós'', "significant") is the study of reference, meaning, or truth. The term can be used to refer to subfields of several distinct disciplines, including philosophy Philosophy (f ...


References


External links

*
Implementing Aggregate root in C# language
* {{Citation , url = http://www.methodsandtools.com/archive/archive.php?id=97 , title = An Introduction to Domain Driven Design , publisher = Methods & tools Software architecture Software design Software development philosophies