Direct Style Effect Systems -The Print[A] Example- A Comprehension Aid
Â
Intro to Domain Driven Design
1. Intro to
Domain Driven
Design
Tackling Complexity in the Heart of Software
“Eric Evans' 2003 book is an essential read for serious software developers” -- Fowler
There are shorter book versions: “distilled”, “quickly”, “kompakt”, “implementing”, “easily”
2. WIIFM
â—Ź Get to know a development approach for complex domains
â—Ź Closer internal stakeholder collaboration
â—Ź Better architecture (loosely-coupled, cohesive)
â—‹ Easier to change
â—‹ Safer to change - less incidents due to inter-team misalignments
â—Ź Companies that exercise DDD were more successful for a long time
â—Ź Can be the basis of future breaking of a monolith
â—Ź Additional paths of refactoring, not only technical
Images from the DDD book and Martin Fowler’s website
4. Ubiquitous Language
â—Ź Have the same terminology: developers, POs, analysts, BI, CS, Designers, QAs
â—Ź In all deliverables: code, documentation, test cases, business cases, sales
â—Ź How? Requirements, talk to domain experts, capture business processes (e.g. event
storming), produce UML, data flow, use industry standards (a.k.a Published Language)
â—Ź Examples: User, Airport, Hotel, Hotel room booked
5. Isolating the domain in the code
Layered Architecture
â—Ź UI / API - expose data, receive commands
â—Ź Application - thin, delegates to domain objects
â—Ź Domain - business concepts and rules
â—Ź Infrastructure - generic technical capabilities
(email, messaging)
6. Building Blocks
â—Ź Entity
â—‹ Has identity, is persisted, is mutable
â—‹ Examples: marked bills, hotel
â—Ź Value Object
â—‹ Defined by its attributes, is immutable, depends on Entity
â—‹ Example: unmarked bills, company address
â—Ź Aggregate - group of entities and value objects.
â—‹ Example: Purchase (the root), invoice, transactions
â—Ź Service
â—‹ Domain business process, has no state
â—‹ Example: book a room
â—Ź Factory
â—‹ A common design pattern for encapsulating the building (non-trivial) objects
â—‹ Example: Computer object
7. Storing and retrieving (working with database)
â—Ź Repository (aggregates persistence)
A common persistence design pattern (in contrast to Rails’ ActiveRecord)
â—‹ Retrieve collections and associations
■Example: retrieve all applications with status “pending” and their associated recruiters
○ Store “unit of work”
â– Example: store a purchase with its invoice and transactions
â—Ź ORM (Object/Relational Mapping)
â—‹ Map between in-memory objects and the database
â—‹ Reduce cognitive load
9. Bounded Context
A “group” of related models and services with explicit interrelations, e.g. Sales and Support
Note that “Customer” exists in both contexts, but might be different models with translation.
Context Map - identify relationships between bounded contexts
10. Inter-Team relationships
â—Ź Shared kernel
â—Ź Customer-supplier
â—Ź Conformist
â—Ź Separate ways
â—Ź Anticorruption layer
Conway’s Law: Any organization that designs a system, will produce a design whose structure is a copy of the organization's communication
structure
11. Supple design - technical aspect to make constant changes easier
12. Distillation - defining subdomains
â—Ź Core Domain
â—‹ e.g. Performance Marketing on job boards
â—Ź Generic Subdomain
â—‹ e.g. User mgmt and permissions
â—Ź Supporting Subdomain
â—‹ e.g. Job lifecycle management
â—Ź Segregated core
â—‹ To refine a complex core domain
13. Additional terminology
â—Ź Domain Events
â—‹ Important events for domain experts (in code or not, inside bounded context or between)
â—Ź Event driven (architecture)
â—‹ Components react to events emitted to a messaging solution
â—Ź Event sourcing (architecture)
â—‹ Event driven where only events are stored, not current states
â—Ź Services / Microservices (architecture)
â—‹ Can compose a bounded context, also third party services
â—Ź Design patterns
â—‹ Examples: Anti corruption layer, composition, abstract factory, factory method, strategy,
adapter
â—Ź CQRS
â—‹ Objects that read are not the objects that write
14. Continuous refinement of the models
â—Ź Domain experts
â—Ź Knowledge crunching
â—Ź Continuous learning
â—Ź Refactoring
15. Common Anti-patterns
â—Ź Implicit communications between cores/bounded contexts thru database
â—Ź Coupling unrelated objects / decoupling related objects
â—Ź Hidden business rules (Utils, small methods)
â—Ź Business logic in wrong layers: UI / Controller / DB
16. Within Ruby and Rails Ecosystem
â—Ź Ruby Modules âś…
â—Ź MVC âś…
â—Ź Thin controllers, service objects âś…
â—Ź ActiveRecord X (but can build repositories that call ActiveRecord scopes)
â—Ź ORM âś…
â—Ź CI âś…
â—Ź Automated tests âś…
â—Ź Refactoring âś…
â—Ź Messaging solutions âś…
17. How to start?
â—Ź Read the book
â—Ź Give an internal tech talk
â—Ź Discuss with team members, other teams, stakeholders
â—Ź Talk to domain experts
â—Ź Have event storming
â—Ź Identify one bounded context, refactor into namespaces
â—Ź Limit direct communication to/from this bounded context
â—Ź Refactor from domain perspective, not only technical
18. How to start?
â—Ź Elevate domain concepts and create explicit policy objects (e.g. VAT)
â—Ź Move logic only into domain objects
â—Ź In architecture evolution, keep DDD in mind
19. Resources
â—Ź The DDD book
â—Ź Eric Evans Talk
â—Ź Object Oriented Software Construction - Bertrand Meyer
â—Ź Working Effectively with Legacy Code - Robert C. Martin
â—Ź Design Patterns. Elements of Reusable Object-Oriented
Software - Erich Gamma
â—Ź https://github.com/ddd-crew/ddd-starter-modelling-process
â—Ź CQRS