**Usage:** Focuses on how we solve the problems we found during domain analysis. **Bounded Context** - A bounded context is a clear boundary around a specific part of the system. - Inside it, terms and rules have one meaning. - Different contexts may use the same word differently. **Note:** It has to be as close as possible to the match a subdomain --- _A bounded context encapsulates the following_ **Entities** - Entities are things with a name or ID that stay the same over time. - They live inside a bounded context. - If another context needs something similar, it creates its own version. **Example:** An entity is a class for a thing that for example, a Supplier : - Has an ID, name, and contact information - Changes over time - Has rules or actions it can take --- **Value Objects** - Value Objects describe something but don’t have an ID. - Their value matters, not who they are. - They don’t change if you need a new value; create a new object. **Example:** An address or a price. --- **Aggregates** - Aggregates group entities and value objects that belong together. - You change them as one unit. - They help make sure the data is always valid. - One entity inside is the "root", you use it to access the rest. - Usually bound to a transaction scope - This means in order to change an aggregate you need to change all the entities inside of it; this way it’s easier to roll back **Example:** In the case of a `Supplier` and its list of `Forms`, the Aggregate root is the `Supplier`, this means changes directly to the `Forms` have to use the `Supplier`, ensuring that business logic is saved and most importantly that its bound to a transaction scope --- **Services** Services are used when logic doesn’t fit into an entity or value object. There are two types: - **Application services:** Handle tasks like sending emails or running use cases. - **Domain services:** Handle business rules that don’t belong to a single object. **Example:** _Domain services_ - Give a discount to `Customer`when they have 3 `Orders` - We need code here that will handle this as it can't belong to `Order` or `Customer`, and call it `DiscountService` - Checking if the email had too many failed login attempts - We need code here that will communicate with the entity User, but also with an external resource that tracks failed attempts --- **Domain Events** - Domain events say “something important happened” inside a context. - They help trigger actions or send messages. - They don’t return results, they just tell others something changed. **Example:** A `SupplierCreated` event could start a process to send a welcome email.