DDD Flashcards
(41 cards)
What is DDD? And what are the main advantages?
DDD - is Domain-Driven Design
What is Bounded Context?
Bounded context is a logical boundary.
What is domain?
Domain is a representation of our reality in the code.
What is tactical pattern?
Focus on items that help you build the model or building block of domain model. ( Entity, DesingPattern )
What is value object?
It’s just a class which responsible for some behavior ( for example Time) Think of them as adjectives in your domain. Value Objects have No identity. Something simular to pure function.
What is Entity?
Domain obejct with unique identity ( Value object with id Model in ActiveRecord ). Usually has mutable state ( you can change name for examlple)
What is aggregate?
It’s a set of composed domain object defining single consistency unit. One aggregate -> One transaction.
Aggregate has one EntryPoint - Root ( Only using this root outer objects can get access to it)
Entities can be grouped into aggregates. For instance, order is an entity, but it can also be an aggregate, which includes two entities: order and order item ( record and its associations )
What is domain event?
- It’s a way to communicate between bounded context
- An object that is used to record a event related to model activity within the system.
What is CQS?
Command–Query Separation (CQS).
Every method should either be a command that performs an action, or a query that returns data to the caller, but not both.
How to split rails models into bounded context?
We can use modules.
admin/product
user/product
sale/product
class Admin::Product < ApplicationRecord end
What can helps us to split big model into the smallest one?
- fields_name ( first_address, second_address)
- prefix/postfix
- some fields updates in one transaction always
Can you provide examples of value objects?
- Time
- Money
- Date
- Point
- Location
Can you provide examples of Entities?
- User
- Customer
- Account
- Banknote ( with serial number)
Can you provide examples of Aggregates?
- Unit
- CreateCar ( many action, authrizers, policies, forms inside)
What the service mean in DDD?
This is a logic which gather some agregates together to perform some action ( Unit as example in our project )
What the command object mean in DDD?
Commands are structures that contain all the attributes necessary to perform an operation in your
system and describe the intention. ( Something like a form with Virtus on our project)
What is Repositories in DDD?
The DDD meaning of a repository is a service that uses a global interface to provide access to all entities and value objects that are within a particular aggregate collection. ( Something simular to query? )
What is Command Bus in DDD?
The command bus matches commands to handlers.
SubmitOrderCommand => method(:submit),
ExpireOrderCommand => method(:expire),
CancelOrderCommand => method(:cancel),
ShipOrderCommand => method(:ship),
I see only one advatadges right now. This allow to set a strict border between clasess/units. You can set restriction to run only action from command bus for example and in this case you won’t be able to run any other action ( outside of this context for example)
Command bus as routing layer but on application level
What rules you should use to select a correct name for domain events?
- Something that alredy happened
- Should be named in past tense…
- Represents a state change,
- Try to use names with business value ( not only CRUD )
What can we do with Domain Events?
- persist in database / event store
- publish it for subscribers using a pub/sub mechanism
What is Event Handler?
This is a logic that receives events and rect to them somehow.
What is the diffirence betweeen Sync and Async events handlers?
- Sync events handlers ( Run event_handler/Subscriber directly after sending event)
- Async event handlers save events to the MessageQueue ( Sidekiq, DelayJob)
Can you give me example of breaking CQS?
when method implement action and actially reaturn changed value
p. next # 1
p. next # 2
The example above don’t break this principle
p. next # nil; # command
p. current # 1 # query
p. next # nil
p. current # 2
What is CQRS?
The Command Query Responsibility Segregation (CQRS) pattern separates read and create/update/delete operations for a data store. The main advantage is reading perfomance improvement.
We can compare it with CRUD. Query it’s READ in CRUD. Command is CREATE, UPDATE, DELETE, or any other operation.