Expanding on our previous article that covered Object-Oriented Analysis and Design (
OOAD), today's article will explore
domain-driven design (
DDD is a software development approach that uses and builds upon
OOADprinciples and ideas, so it's the next logical topic for us to dive into.
Throughout this article we'll examine what
domain-driven design is, how it is commonly implemented in modern development life cycles, and consider a few potential advantages and disadvantages of using
DDD in your own projects. Let's get crackin'!
domain-driven design we should first establish what we mean by
domain in this context (and in development in general). The common dictionary definition of
domain is: "A sphere of knowledge or activity." Drilling down a bit from that,
domain in the realm of software engineering commonly refers to the subject area on which the application is intended to apply. In other words, during application development, the
domain is the "sphere of knowledge and activity around which the application logic revolves."
Another common term used during software development is the
domain layer or
domain logic, which may be better known to many developers as the
business logic. The
business logic of an application refers to the higher-level rules for how
business objects (see:
OOAD) interact with one another to create and modify modelled data.
Initially introduced and made popular by programmer Eric Evans in his 2004 book, Domain-Driven Design: Tackling Complexity in the Heart of Software,
domain-driven design is the expansion upon and application of the
domainconcept, as it applies to the development of software. It aims to ease the creation of complex applications by connecting the related pieces of the software into an ever-evolving model.
DDD focuses on three core principles:
domain experts, in order to improve the application model and resolve any emerging
Evans' Domain-Driven Design further defines a few common terms that are useful when describing and discussing
domainand can be used to solve problems related to that
domain modeland used by all team members to connect all the activities of the team with the software.
Domain-driven design also defines a number of high-level concepts that can be used in conjunction with one another to create and modify
objectthat is identified by its consistent thread of continuity, as opposed to traditional
objects, which are defined by their
attributes, but no distinct identity.
domain eventis only created for event types which the
domain expertscare about.
value objectswith defined boundaries around the group. Rather than allowing every single
value objectto perform all actions on its own, the collective
aggregateof items is assigned a singular
aggregate rootitem. Now, external objects no longer have direct access to every individual
value objectwithin the
aggregate, but instead only have access to the single
aggregate rootitem, and use that to pass along instructions to the group as a whole. This practice correlates with many of the actual coding practices we're covering in our
serviceis an operation or form of business logic that doesn't naturally fit within the realm of
objects. In other words, if some functionality must exist, but it cannot be related to an
value object, it's probably a
version control repositories, the
DDDmeaning of a
servicethat uses a global interface to provide access to all
value objectsthat are within a particular
aggregatecollection. Methods should be defined to allow for creation, modification, and deletion of objects within the
aggregate. However, by using this
serviceto make data queries, the goal is to remove such data query capabilities from within the business logic of
design patternsarticles already,
DDDsuggests the use of a
factory, which encapsulates the logic of creating complex objects and
aggregates, ensuring that the client has no knowledge of the inner-workings of object manipulation.
Domain-driven design also heavily emphasizes the ever-more-popular practice of
continuous integration, which asks the entire development team to use one shared code repository and push commits to it daily (if not multiple times a day). An automatic process executes at the end of the work day, which checks the integrity of the entire code base, running automated unit tests, regression tests, and the like, to quickly detect any potential problems that may have been introduced in the latest commits.
ubiquitouslanguage related to the
domain modelof the project, teams will often find communication throughout the entire development life cycle to be much easier. Typically,
DDDwill require less technical jargon when discussing aspects of the application, since the
ubiquitous languageestablished early on will likely define simpler terms to refer to those more technical aspects.
DDDis so heavily based around the concepts of
object-oriented analysis and design, nearly everything within the
domain modelwill be based on an object and will, therefore, be quite modular and encapsulated. This allows for various components, or even the entire system as a whole, to be altered and improved on a regular, continuous basis.
DDDis the practice of building around the concepts of
domainand what the
domain expertswithin the project advise,
DDDwill often produce applications that are accurately suited for and representative of the
domainat hand, as opposed to those applications which emphasize the UI/UX first and foremost. While an obvious balance is required, the focus on
domainmeans that a
DDDapproach can produce a product that resonates well with the audience associated with that
domain experton the team that knows the exact ins and outs of the subject area on which the application is intended to apply. In some cases,
domain-driven designmay require the integration of one or more outside team members who can act as
domain expertsthroughout the development life cycle.
DDDpractices strongly rely on constant iteration and continuous integration in order to build a malleable project that can adjust itself when necessary. Some organizations may have trouble with these practices, particularly if their past experience is largely tied to less-flexible development models, such as the
waterfallmodel or the like.
DDDis great for applications where there is a great deal of
business logicis rather complex and convoluted),
DDDis not very well-suited for applications that have marginal
domaincomplexity, but conversely have a great deal of technical complexity. Since
DDDso heavily emphasizes the need for (and importance of)
domain expertsto generate the proper
ubiquitous languageand then
domain modelon which the project is based, a project that is incredibly technically complex may be challenging for
domain expertsto grasp, causing problems down the line, perhaps when technical requirements or limitations were not fully understood by all members of the team.