Skip to content

Building Blocks (Tactical Patterns)

  1. Entities: Entities are objects that have their own identity and are fundamental to domain modeling. Each entity is uniquely identified, which allows its state to be tracked over time. For example, in a library system, a book can be considered an entity, as it has attributes like title, author, ISBN, and availability status. Similarly, a reader is also an entity, with attributes like name, identification number, and loan history. This identity is crucial as it ensures that operations and interactions with these entities are accurate and consistent, allowing the system to faithfully reflect the reality of the domain being modeled.

  2. Repositories: Repositories play a central role in data persistence, being responsible for retrieving and storing entities and aggregates. They act as a bridge between the application's business logic and the data persistence layer, such as a database. The main function of a repository is to provide an interface for manipulating entities, allowing operations like adding, finding, updating, and removing objects. For example, in a library system, a BookRepository might offer methods to find books by title, author, or ISBN. This abstraction simplifies implementation, allowing developers to focus on business logic without worrying about the details of how data is stored and retrieved.

  3. Services: Services encapsulate business logic that does not fit neatly into entities or Value Objects. They are responsible for performing operations that may involve multiple entities or require complex business rules. For example, in an e-commerce system, a service might calculate the total value of an order, considering item prices, discounts, taxes, and shipping fees. This logic can be much more complex than simply summing values, as it may include specific rules for applying discounts depending on the customer type or the total order value. By keeping this logic in a separate service, the code becomes more modular and easier to maintain, allowing developers to isolate and test this logic efficiently without interfering with entities or data persistence.

  4. Controllers (MVC): In the context of software development, especially in web applications, a Controller is a component that acts as an intermediary between the user interface (UI) and the application's business logic. It is responsible for managing user requests, processing these requests, interacting with services, and returning the appropriate responses.

ClientControllerServiceRepositoryEntityClientClientControllerControllerServiceServiceRepositoryRepositoryEntityEntityExecutes anoperation in the systemUnpacks messagefrom the protocol (HTTP, AMQP, etc.),sends to the service layerOrchestrates rulesbetween dependent dataExecutes a query on thedatabase abstractionlayerReturns dataencapsulated in the entityReturns the requesteddataset of entitiesReturns the processedand orchestrated data,ready for consumptionWraps the datain the protocol chosenby the application and delivers it