08 Dec 2023
Domain-driven design (DDD) is a way of building software that focuses on understanding and modeling the real-world problems that the software is trying to solve. It's like creating a blueprint for the software that is based on the knowledge and expertise of people who know the most about the problem domain, such as business experts, users, and engineers.
Summary of key concepts in Domain-Driven Design:
-
Domain: In the context of Domain-Driven Design (DDD), the term "domain" refers to a specific area of expertise or knowledge that a software application is designed to address. It encompasses the concepts, rules, and relationships that govern a specific problem space or business area. DDD emphasizes modeling software to match a domain according to input from domain experts. This means that the structure and language of software code should reflect the real-world terms and concepts of the domain.
- Example: The domain for example is
eCommerce. This encompasses all aspects of buying and selling products online, from browsing and ordering to payment and fulfillment.
- Example: The domain for example is
-
Ubiquitous Language: Ubiquitous Language (UL) refers to the practice of using a common and shared language (or vocabulary ) throughout the entire software development process in Domain-Driven Design (DDD). This language is used by both technical and non-technical team members to ensure a clear and consistent understanding of the domain and its complexities. By maintaining a ubiquitous language, everyone involved in the project can communicate more effectively, leading to better collaboration, reduced misunderstandings, and a more successful software development process.
- Example: In eCommerce, examples of ubiquitous language terms include "product", "cart", "order", "customer", "inventory", and "shipment".
-
Domain Model: A conceptual model representing the core domain entities, their relationships, and behavior of that domain. It maps the real-world concepts to software entities.It is created by working with domain experts and software developers to create a shared understanding of the domain. It serves as the blueprint for the system's design.The domain model is then used to guide the design and implementation of software systems that accurately reflect the real world.
-
Bounded Contexts: Bounded Context is like a mini-domain within a larger domain. It has its own unique rules, vocabulary, and team of experts. This helps to break down a large and complex domain into more manageable pieces, making it easier to understand and develop software for.
- Example: In eCommerce, separate bounded contexts might exist for product management, order processing, and customer relationship management.
-
Entities: An entity is an object that represents a real-world thing. Entities are objects that have a unique identity and can change over time. Entities are typically persisted in a database, but they can also be stored in memory or other data stores.
- Example: Entities in eCommerce include Product, Order, Customer, and ShoppingCart.
-
Value objects: Value objects are typically immutable objects(meaning that they cannot be changed once they are created). They do not have a unique identity. Value objects are often used to model quantities, dimensions, and other characteristics of entities.
- Example: Value objects in eCommerce include Money, Address, and ProductDimensions.
-
Aggregates: In Domain-Driven Design (DDD), an aggregate is a group of closely related domain objects treated as a singular unit. These aggregates comprise both entities and value objects, seen as a tightly connected whole.
- Example: In e-commerce, an Order aggregate might include the Order entity, its associated OrderItems, and the ShippingAddress and BillingAddress value objects.
-
Shared Kernel: A Shared Kernel in Domain-Driven Design (DDD) is a set of domain concepts and code that is shared by multiple bounded contexts. A bounded context is a conceptual boundary within a software system that separates different aspects of the domain. By sharing a kernel, bounded contexts can use the same domain concepts and code, which helps to ensure consistency and avoid duplication.
- Example: User authentication might be a Shared Kernel that is used across different contexts in eCommerce.
-
Repositories: Repositorys serve as a bridge between the application layer (where business logic resides) and the persistence layer (where data is stored).They typically offer abstraction methods for basic CRUD operations (create, read, update, delete) on domain objects. Moreover, they facilitate querying and provide methods for searching, filtering, and managing the storage and retrieval of these entities from a database or any underlying data source.
- Example: In eCommerce, a repository might be used to store and retrieve orders, customers, and products.
-
Services: Services are reusable classes that encapsulate business logic and operations. They are responsible for performing complex operations, such as business rules validation, calculations, coordination of multiple entities etc..
- Example: Order Processing Service, Payment Gateway Service, Product Catalog Service, Inventory Management Service, Promotion and Discount Service, Notification Service etc.
-
Domain Events: An event is something that has already happened. A domain event is a specific type of event that occurs within a particular domain. When a domain event occurs, other parts of the same domain are notified so that they can take appropriate action.
- Example: In eCommerce, a domain event could be "OrderPlaced" or "ProductShipped."
-
Factories: Factories play a crucial role in Domain-Driven Design (DDD) by encapsulating the logic for creating and configuring domain objects. They provide a centralized location for managing object instantiation and simplify the process of constructing complex objects.
- Example: In eCommerce, a CartFactory might create a new shopping cart with default settings.
-
Anti-Corruption Layer: Is a layer of abstraction that sits between the domain model and external systems. It is responsible for translating between the domain model and the foreign data models and APIs of those external systems. The goal of the ACL is to protect the domain model from being corrupted by the foreign concepts and models of the external systems.
- Example: In eCommerce,
- Taxation Adapter: Ensures consistency in applying taxes across different contexts.
- User Authentication Bridge: Facilitates secure user authentication between the user management and order processing contexts.
- Inventory Sync Adapter: Synchronizes product availability information between the inventory management and order processing contexts.
- Example: In eCommerce,
-
Context mapping: Context mapping is a strategic modeling tool used in Domain-Driven Design (DDD) to visualize and understand the relationships between bounded contexts within a software system. It helps to identify and clarify the boundaries between different areas of domain knowledge, fostering a common understanding among domain experts, developers, and stakeholders.
- Example: In eCommerce, context mapping helps establish clear boundaries between order processing and inventory management.
-
Strategic Design: Strategic design in DDD is the process of defining the high-level architecture of a software system, including the identification of bounded contexts, the ubiquitous language, and the context maps. It is a collaborative process between domain experts and technical experts, and it is essential for ensuring that the system is aligned with the business needs and that it is maintainable and scalable.
- Example: In eCommerce, it might involve choosing the right Bounded Contexts, defining the Shared Kernel, and establishing context boundaries.
-
Continuous Refinement: Continuous refinement in DDD is the ongoing process of improving the domain model over time. This is done by iteratively making adjustments and adaptations based on feedback from domain experts and stakeholders. This ensures that the software system remains aligned with the changing needs of the business.
- Example: software remains aligned with the business needs in the dynamic eCommerce environment.