Domain-Driven Design

34
Domain-Driven Design Andriy Buday http://andriybuday.com/

description

Domain-Driven Design

Transcript of Domain-Driven Design

Page 1: Domain-Driven Design

Domain-Driven Design

Andriy Budayhttp://andriybuday.com/

Page 2: Domain-Driven Design

Yeah… I’ve read them all…

Page 3: Domain-Driven Design

Where is a car on the left or on the right?

Introduction

We cannot just type the code… we need to have a vision…

Page 4: Domain-Driven Design

What is DDD? Ubiquitous Language New architecture Building blocks of Domain-Driven Design Refactoring Toward Deeper Insight Preserving Model Integrity Infrastructure Patterns and practices with Domain-Driven Design

Outline

Page 5: Domain-Driven Design

DDD is an approach to the design Model is the heart of the DDD

Model and the design shape each other Model is language for team members Model is knowledge

Your Focus is on heart

Domain-Driven Design

Page 6: Domain-Driven Design

Need for some common language Language and model How does it look?

Speech (a common) Diagrams Writing (not long documents) UML (not cumbersome)

UBIQUITOUS LANGUAGE

Page 7: Domain-Driven Design

Voyage Cargo

Page 8: Domain-Driven Design

Voyage Cargo

Page 9: Domain-Driven Design

Voyage Cargo

Page 10: Domain-Driven Design

How will you build your architecture with DDD?

New Architecture

Page 11: Domain-Driven Design

Advantages Disadvantages Bottom line

The Smart UI “Anti-Pattern”

Page 12: Domain-Driven Design

Layered architecture

Page 13: Domain-Driven Design

Building blocks of DDD

Page 14: Domain-Driven Design

Entities

Page 15: Domain-Driven Design

Almost like a Entity but without Identity

Value Objects

Page 16: Domain-Driven Design

Address for Patient could be Value Object…because it doesn’t play huge role in his treating

Address in postal service is Entity…because it is critical to know where to deliver

correspondence

Value Object or Entity? Who is asking?

Page 17: Domain-Driven Design

Three characteristics for a good Service: Operation not natural to an Entity or Value Object Defined interface Operation is stateless

Service

Page 18: Domain-Driven Design

When you place some classes together in a Module, you are telling the next developer who looks at your design to think about them together.

Modules

Page 19: Domain-Driven Design

Aggregate

Car is Aggregate to Tire Root Entity

Page 20: Domain-Driven Design

Responsibility of Factory Requirements to Factory

Atomicity Abstracted to the type desired

Reconstituting Stored Objects

Factory

Page 21: Domain-Driven Design

Querying a Repository Implementation of Repository

Abstract the type. Take advantage of the decoupling from the client. Leave transaction control to the client.

Repositories

Page 22: Domain-Driven Design

Factories and Repositories

Page 23: Domain-Driven Design

Continuous Refactoring Refactoring toward deeper insight is not the same kind as

technical refactoring. We could not have patterns of doing it.

Bring Key Concepts into Light There are times when lots of small changes add very little

value to the design, and here are times when few changes make a lot of difference.

Refactoring Toward Deeper Insight

Page 24: Domain-Driven Design

Constraint Process Specification

Bring Concepts Into Light

Customer customer = customerRepository.findCustomer(customerIdentiy);

//…

Specification customerEligibleForRefund = new Specification(

        new CustomerPaidHisDebtsInThePast(),

        new CustomerHasNoOutstandingBalances() );

if (customerEligibleForRefund.isSatisfiedBy(customer))

{

        refundService.issueRefundTo(customer);

}

Page 25: Domain-Driven Design

Preserving Model Integrity

Page 26: Domain-Driven Design

Each model has a context When we deal with legacy we create new model

and new context A model should be small enough to be assigned to

one team Continuous Integration Context Map (document)

Bounded Context

Page 27: Domain-Driven Design

Shared Kernel Customer-Supplier Conformist Anticorruption Layer Separate Ways Open Host Service Distillation

Interaction between different contexts

Page 28: Domain-Driven Design

Persistence Ignorance

Prepare your Infrastructure

Page 29: Domain-Driven Design

How do we classify ORMs? How do they resolve issues? Requirements to them Identity Map Unit Of Work Lazy load

Infrastructure: ORM

Page 30: Domain-Driven Design

NHibernate provides all the features required to quickly build an advanced persistence layer in code.

You work only with objects, so you understand Business model.

NHibernate

Page 31: Domain-Driven Design

Agile techniques are good for DDD

…such as TDD…

New way of proecting

…such as SOA, AOP, IoC…

Patterns and practices with Domain-Driven Design

Page 33: Domain-Driven Design

Read blog! Follow me! Visit Lviv UG!

@andriybuday

http://andriybuday.com/

http://dotnetug-lviv.blogspot.com/

[email protected]

Page 34: Domain-Driven Design