Domain-driven Design - Building Blocks of DDD

Building Blocks of DDD

In the book Domain-Driven Design, a number of high-level concepts and practices are articulated, such as ubiquitous language meaning that the domain model should form a common language given by domain experts for describing system requirements, that works equally well for the business users or sponsors and for the software developers. The book is very focused at describing the domain layer that is one of the common layers in an object-oriented system with a multilayered architecture. In DDD, there are artifacts to express, create, and retrieve domain models:

  • Entity: An object that is not defined by its attributes, but rather by a thread of continuity and its identity.

Example: Most airlines distinguish each seat uniquely on every flight. Each seat is an entity in this context. However, Southwest Airlines (or EasyJet/RyanAir for Europeans) does not distinguish between every seat; all seats are the same. In this context, a seat is actually a value object.

  • Value Object: An object that contains attributes but has no conceptual identity. They should be treated as immutable.

Example: When people exchange dollar bills, they generally do not distinguish between each unique bill; they only are concerned about the face value of the dollar bill. In this context, dollar bills are value objects. However, the Federal Reserve may be concerned about each unique bill; in this context each bill would be an entity.

  • Aggregate: A collection of objects that are bound together by a root entity, otherwise known as an aggregate root. The aggregate root guarantees the consistency of changes being made within the aggregate by forbidding external objects from holding references to its members.

Example: When you drive a car, you do not have to worry about moving the wheels forward, making the engine combust with spark and fuel, etc.; you are simply driving the car. In this context, the car is an aggregate of several other objects and serves as the aggregate root to all of the other systems.

  • Service: When an operation does not conceptually belong to any object. Following the natural contours of the problem, you can implement these operations in services. The Service concept is called "Pure Fabrication" in GRASP.
  • Repository: methods for retrieving domain objects should delegate to a specialized Repository object such that alternative storage implementations may be easily interchanged.
  • Factory: methods for creating domain objects should delegate to a specialized Factory object such that alternative implementations may be easily interchanged.

Read more about this topic:  Domain-driven Design

Famous quotes containing the words building and/or blocks:

    And no less firmly do I hold that we shall one day recognize in Freud’s life-work the cornerstone for the building of a new anthropology and therewith of a new structure, to which many stones are being brought up today, which shall be the future dwelling of a wiser and freer humanity.
    Thomas Mann (1875–1955)

    In any case, raw aggression is thought to be the peculiar province of men, as nurturing is the peculiar province of women.... The psychologist Erik Erikson discovered that, while little girls playing with blocks generally create pleasant interior spaces and attractive entrances, little boys are inclined to pile up the blocks as high as they can and then watch them fall down: “the contemplation of ruins,” Erikson observes, “is a masculine specialty.”
    Joyce Carol Oates (b. 1938)