Introduction to-ddd

34
John Ferguson Smart software that reflects the business domain Domain Driven Design

description

An introductory talk on Domain Driven Development.

Transcript of Introduction to-ddd

Page 1: Introduction to-ddd

John Ferguson Smart

software that reflects the business domain

Domain Driven Design

Page 2: Introduction to-ddd

So who is this guy, anyway?

John Ferguson Smart

ConsultantTrainerMentorAuthorSpeakerCoder

Page 3: Introduction to-ddd

What is Domain-Driven Design?

Page 4: Introduction to-ddd

Domain-driven design is not a technology or a methodology.

Page 5: Introduction to-ddd

It’s a set of principles and patterns for focusing design effort where it matters most.

Page 6: Introduction to-ddd

Basic principles

Page 7: Introduction to-ddd

Basic principles

Focus on the domain

Domain design is based on a model

Page 8: Introduction to-ddd

Basic principles

A Ubiquitous Language...

...and a shared vision

Page 9: Introduction to-ddd

So what’s a model?

Page 10: Introduction to-ddd
Page 11: Introduction to-ddd
Page 12: Introduction to-ddd
Page 13: Introduction to-ddd

How do you represent your domain model?

Page 14: Introduction to-ddd

How do you represent your domain model?

Customer Account

Branch

(UML) Diagrams?

Page 15: Introduction to-ddd

How do you represent your domain model?

Detailed specifications?

Page 16: Introduction to-ddd

How do you represent your domain model?

Account Holder withdraws cash As an account holderI want to withdraw cash from an ATM so that I can get money out when the bank is closed

Scenario 1: Account has sufficient funds Given the account balance is $100 And the card is valid And the machine contains enough money When the Account Holder requests $20 Then the ATM should dispense $20 And the account balance should be $80 And the card should be returned

Scenario 2: Account has insufficient funds Given the account balance is $10 And the card is valid And the machine contains enough money When the Account Holder requests $20 The ATM should not dispense any money

Free text?

Page 17: Introduction to-ddd

@Test public void aCashWithdrawalShouldDeductSumFromBalance() { Account account = new Account(); account.makeDeposit(100); account.makeCashWithdraw(60); assertThat(account.getBalance(), is(40)); }

How do you represent your domain model?

Automated tests?

Page 18: Introduction to-ddd

class Account(val owner : Customer, val accountNumber : String, val accountType : AccountType, var balance : Double) {

def deposit(amount : Double) { balance += amount } def withdraw(amount : Double) { balance -= amount }}

class Customer(val firstName : String, val lastName : String) {

createAccount(accountType : AccountType) : Account}

class AccountType extends Enumeration { val Current = value("CURRENT") val Savings = value("SAVINGS")}

How do you represent your domain model?

Code?

Page 19: Introduction to-ddd

The model is the mental representation

Everything else is just a communication tool

Page 20: Introduction to-ddd

Elaborating the model

Page 21: Introduction to-ddd

Elaborating the model

A collaborative exercise

Page 22: Introduction to-ddd

Elaborating the model

...based on a common language

Page 23: Introduction to-ddd

Elaborating the model

...and expressed at all levels

Account Holder withdraws cash As an account holderI want too withdraw cash from an ATM so that I can get money out when the bank is closed

@Test public void aCashWithdrawalShouldDeductSumFromBalance() { Account account = new Account(); account.makeDeposit(100); account.makeCashWithdraw(60); assertThat(account.getBalance(), is(40));}

Page 24: Introduction to-ddd

Elaborating the model

An evolutionary process

Page 25: Introduction to-ddd

Elaborating the model

So testing is essential

Page 26: Introduction to-ddd

Elaborating the model

...automated testing is essential

Test

Page 27: Introduction to-ddd

Domain-Driven Design practices

Page 28: Introduction to-ddd

Domain-Driven Design architecture

Presenta(on  Layer

Applica(on  Layer

Domain  Layer

Infrastructure  Layer

User Interface

Service layerStateless

domain knowledge and business logic

supporting librariespersistencemessaging

Page 29: Introduction to-ddd

Domain-Driven Design architecture

Entities• Identify and state• Persistence

Page 30: Introduction to-ddd

Domain-Driven Design architecture

Value  Objects• No conceptual identity• Immutable

Page 31: Introduction to-ddd

Domain-Driven Design architecture

Services• Domain-level services• Stateless

Page 32: Introduction to-ddd

Domain-Driven Design architecture

Repositories• Data retrieval• Abstraction of the persistence layer

Page 33: Introduction to-ddd

Domain-Driven Design architecture

Factories• Creation of complex entities

Page 34: Introduction to-ddd

Application code should be a reflection of the business domain

John  Ferguson  SmartEmail:  [email protected]:  hAp://www.wakaleo.com

TwiAer:  wakaleo