98
How to (finally) start doing DDD by using BDD

How to (finally) start doing DDD by using BDD

Embed Size (px)

Citation preview

Page 1: How to (finally) start doing DDD by using BDD

How to (finally) start doing

DDD by using BDD

Page 2: How to (finally) start doing DDD by using BDD

Kacper Gunia @cakper

So!ware Engineer @SensioLabsUK / @Inviqa

PHPers Silesia @PHPersPL

Page 3: How to (finally) start doing DDD by using BDD

What is BDD?

Page 4: How to (finally) start doing DDD by using BDD

Bug-drivenDevelopment ;)

Page 5: How to (finally) start doing DDD by using BDD

Behaviour-driven development is about implementing an application

by describing its behaviour from the perspective of its

stakeholders.-- Dan North

Page 6: How to (finally) start doing DDD by using BDD

BDD is about establishing a shared understanding of “done”

working from the outside in until you get there

-- Dan North

Page 7: How to (finally) start doing DDD by using BDD

BDD shows you what to do nextaka Technical Discipline

Page 8: How to (finally) start doing DDD by using BDD

How do we BDD?

Page 9: How to (finally) start doing DDD by using BDD

Feature: Traveler searches for cheap itineraries In order to save money while travelling As a world traveler I want to search for the cheapest itinerary

Page 10: How to (finally) start doing DDD by using BDD

Product owner writes scenarioand developer automates it

Page 11: How to (finally) start doing DDD by using BDD

Developer writes scenarioand then automates it

Page 12: How to (finally) start doing DDD by using BDD

No!

Page 13: How to (finally) start doing DDD by using BDD

BDD is about communication!

flickr.com/photos/dvids/5638829762

Page 14: How to (finally) start doing DDD by using BDD
Page 15: How to (finally) start doing DDD by using BDD

Scenario: Successfully find cheapest direct flight Given the flight from "WAW" to "LHR" priced $30 was scheduled And the flight from "WAW" to "LHR" priced $50 was scheduled When I open the "/search" page And I fill "WAW" in the "Departure airport" field And I fill "LHR" in the "Destination airport" field And I click "Search" Then I should be redirected to "/results" page And I should see $30 in the "#cheapest-flight-price" block

Page 16: How to (finally) start doing DDD by using BDD
Page 17: How to (finally) start doing DDD by using BDD
Page 18: How to (finally) start doing DDD by using BDD

Scenario: Successfully find cheapest direct flight Given the flight from "WAW" to "LHR" priced $30 was scheduled And the flight from "WAW" to "LHR" priced $50 was scheduled When I open the "/search" page And I fill "WAW" in the "Departure airport" field And I fill "LHR" in the "Destination airport" field And I click "Search" Then I should be redirected to "/results" page And I should see $30 in the "#cheapest-flight-price" block

Page 19: How to (finally) start doing DDD by using BDD
Page 20: How to (finally) start doing DDD by using BDD

Translation

Page 21: How to (finally) start doing DDD by using BDD

Can we do better?

Page 22: How to (finally) start doing DDD by using BDD
Page 23: How to (finally) start doing DDD by using BDD
Page 24: How to (finally) start doing DDD by using BDD
Page 25: How to (finally) start doing DDD by using BDD

Mission accomplished BoysWe can go home now!

flickr.com/photos/dvids/5638829762

Page 26: How to (finally) start doing DDD by using BDD
Page 27: How to (finally) start doing DDD by using BDD
Page 28: How to (finally) start doing DDD by using BDD

Translation again

Page 29: How to (finally) start doing DDD by using BDD

How to fix that?

Page 30: How to (finally) start doing DDD by using BDD

DDD

Page 31: How to (finally) start doing DDD by using BDD

What is DDD about?

Page 32: How to (finally) start doing DDD by using BDD

It’s about focusing on the domain and letting it affect the so"ware very

much-- Jimmy Nilsson

Page 33: How to (finally) start doing DDD by using BDD

But WHY do we need it?

Page 34: How to (finally) start doing DDD by using BDD

Everybody knows the jargonin their OWN FIELD

Page 35: How to (finally) start doing DDD by using BDD

It's about common understanding

Page 36: How to (finally) start doing DDD by using BDD

Ubiquitous language

Page 37: How to (finally) start doing DDD by using BDD
Page 38: How to (finally) start doing DDD by using BDD
Page 39: How to (finally) start doing DDD by using BDD
Page 40: How to (finally) start doing DDD by using BDD

Concrete examples are rooted in the problem domain

-- Matt Wynne

Page 41: How to (finally) start doing DDD by using BDD
Page 42: How to (finally) start doing DDD by using BDD

Domain Model

Page 43: How to (finally) start doing DDD by using BDD

A domain model (...) is not just the knowledge in a domain expert’s head;

it is a rigorously organized and selective abstraction of that knowledge

-- Eric Evans

Page 44: How to (finally) start doing DDD by using BDD

Model documentsthe knowledge

Page 45: How to (finally) start doing DDD by using BDD

Pushing for ubiquitous language hard enough makes your examples a domain

model-- Konstantin Kudryashov

Page 46: How to (finally) start doing DDD by using BDD

Scenario: Successfully find cheapest direct flight Given the flight from "WAW" to "LHR" priced $30 was scheduled And the flight from "WAW" to "LHR" priced $50 was scheduled When I open the "/search" page And I fill "WAW" in the "Departure airport" field And I fill "LHR" in the "Destination airport" field And I click "Search" Then I should be redirected to "/results" page And I should see $30 in the "#cheapest-flight-price" block

Page 47: How to (finally) start doing DDD by using BDD

Scenario: Successfully find cheapest direct itinerary Given the search for the itinerary schedule And the itinerary from "WAW" to "LHR" priced $30 was planned in the schedule And the itinerary from "WAW" to "LHR" priced $50 was planned in the schedule When I search for cheapest itinerary from "WAW" to "LHR" Then the cheapest itinerary should cost $30

Page 48: How to (finally) start doing DDD by using BDD

Modelling by example

Page 49: How to (finally) start doing DDD by using BDD
Page 50: How to (finally) start doing DDD by using BDD
Page 51: How to (finally) start doing DDD by using BDD

Phase 1

Page 52: How to (finally) start doing DDD by using BDD
Page 53: How to (finally) start doing DDD by using BDD

Scenario: Successfully find cheapest direct itinerary Given the search for the itinerary schedule And the itinerary from "WAW" to "LHR" priced $30 was planned in the schedule And the itinerary from "WAW" to "LHR" priced $50 was planned in the schedule When I search for cheapest itinerary from "WAW" to "LHR" Then the cheapest itinerary should cost $30

Page 54: How to (finally) start doing DDD by using BDD
Page 55: How to (finally) start doing DDD by using BDD

Given the search for the itinerary schedule

/** * @Given /^the search for the itinerary schedule$/ */ public function theSearchForTheItinerarySchedule() { $this->itinerarySchedule = new ItinerarySchedule(); $this->search = new Search($this->itinerarySchedule); }

Page 56: How to (finally) start doing DDD by using BDD
Page 57: How to (finally) start doing DDD by using BDD

Design emerges

Page 58: How to (finally) start doing DDD by using BDD

And the itinerary from "WAW" to "LHR" priced $30 was planned in the schedule

/** * @Given the itinerary from :fromAirport to :toAirport * priced $:price was planned in the schedule */ public function theItineraryFromToPricedWasPlannedInTheSchedule( $fromAirport, $toAirport, $price ) { $itinerary = new Itinerary( Airport::code($fromAirport), Airport::code($toAirport), Money::usd($price) );

$this->itinerarySchedule->plan($itinerary); }

Page 59: How to (finally) start doing DDD by using BDD
Page 60: How to (finally) start doing DDD by using BDD

When I search for cheapest itinerary from "WAW" to "LHR"

/** * @When I search for cheapest itinerary from :fromAirport to :toAirport */ public function iSearchForCheapestItineraryFromTo($fromAirport, $toAirport) { $this->cheapestItinerary = $this->search->forCheapest( Airport::code($fromAirport), Airport::code($toAirport) ); }

Page 61: How to (finally) start doing DDD by using BDD

Then the cheapest itinerary should cost $30

/** * @Then the cheapest itinerary should cost $:price */ public function theCheapestItineraryShouldCost($price) { expect($this->cheapestItinerary->cost())->toBeLike(Money::usd($price)); }

Page 62: How to (finally) start doing DDD by using BDD
Page 63: How to (finally) start doing DDD by using BDD
Page 64: How to (finally) start doing DDD by using BDD

Phase 2

Page 65: How to (finally) start doing DDD by using BDD
Page 66: How to (finally) start doing DDD by using BDD

@ui Scenario: Successfully find cheapest direct itinerary Given the search for the itinerary schedule And the itinerary from "WAW" to "LHR" priced $30 was planned in the schedule And the itinerary from "WAW" to "LHR" priced $50 was planned in the schedule When I search for cheapest itinerary from "WAW" to "LHR" Then the cheapest itinerary should cost $30

Page 67: How to (finally) start doing DDD by using BDD

Given the search for the itinerary schedule

/** * @Given the search for the itinerary schedule */ public function theSearchForTheItinerarySchedule() { $this->visit("/search"); }

Page 68: How to (finally) start doing DDD by using BDD

And the itinerary from "WAW" to "LHR" priced $30 was planned in the schedule

/** * @Given the itinerary from :fromAirport to :toAirport * priced $:price was planned in the schedule */ public function theItineraryFromToPricedWasPlannedInTheSchedule( $fromAirport, $toAirport, $price ) { $itinerary = new Itinerary( Airport::code($fromAirport), Airport::code($toAirport), Money::usd($price) );

$this->get("itinerary_schedule")->plan($itinerary); }

Page 69: How to (finally) start doing DDD by using BDD

When I search for cheapest itinerary from "WAW" to "LHR"

/** * @When I search for cheapest itinerary from :fromAirport to :toAirport */ public function iSearchForCheapestItineraryFromTo($fromAirport, $toAirport) { $this->fillIn("#from-airport", $fromAirport); $this->fillIn("#to-airport", $toAirport);

$this->clickButton("Search"); }

Page 70: How to (finally) start doing DDD by using BDD

Then the cheapest itinerary should cost $30

/** * @Then the cheapest itinerary should cost $:price */ public function theCheapestItineraryShouldCost($price) { $cheapestItinerary = $this->find("#cheapest-itinerary"); expect($cheapestItinerary)->toContainText(sprintf("From $%s", $price)); }

Page 71: How to (finally) start doing DDD by using BDD

# behat.yml default: suites: domain: contexts: [ SearchContext ] ui: contexts: [ WebSearchContext ] filters: { tags: '@ui' }

Page 72: How to (finally) start doing DDD by using BDD

Modelling by ExampleIn three (easy) steps

Page 73: How to (finally) start doing DDD by using BDD

· Have the conversation· Model your objects

· Go again through UI*

Page 74: How to (finally) start doing DDD by using BDD

*But

Page 75: How to (finally) start doing DDD by using BDD

You (really) don't have to automate

everything!

Page 76: How to (finally) start doing DDD by using BDD
Page 77: How to (finally) start doing DDD by using BDD

But there is a problem

Page 78: How to (finally) start doing DDD by using BDD

We ignored the depth of the domain

Page 79: How to (finally) start doing DDD by using BDD

On purpose

Page 80: How to (finally) start doing DDD by using BDD

You can't model the whole system using

one feature

Page 81: How to (finally) start doing DDD by using BDD
Page 82: How to (finally) start doing DDD by using BDD

Repeat the process and model the

planner

Page 83: How to (finally) start doing DDD by using BDD

What if model has different requirements

in this context?

Page 84: How to (finally) start doing DDD by using BDD

Bounded Context

Page 85: How to (finally) start doing DDD by using BDD

Language is limited

Page 86: How to (finally) start doing DDD by using BDD

Search Itinerary!=

Planner Itinerary!=

Booking Itinerary

Page 87: How to (finally) start doing DDD by using BDD
Page 88: How to (finally) start doing DDD by using BDD

Do not build fragile monoliths!

Page 89: How to (finally) start doing DDD by using BDD

Build applications withBounded context in mind

Page 90: How to (finally) start doing DDD by using BDD

--- Wrap up ---

Page 91: How to (finally) start doing DDD by using BDD

Have the conversation

Page 92: How to (finally) start doing DDD by using BDD

Do not separate the concepts from the implementation

Page 93: How to (finally) start doing DDD by using BDD

You cannot build conceptual models

without considering implementation issues

Page 94: How to (finally) start doing DDD by using BDD

Push forUbiquitous language

Page 95: How to (finally) start doing DDD by using BDD

Use Behat to drive your ModelNot only the UI

Page 96: How to (finally) start doing DDD by using BDD

"BDD is about conversations you have to

produce software"

Page 97: How to (finally) start doing DDD by using BDD

"DDD is about how youexplore domain models

and how you articulate this"

Page 98: How to (finally) start doing DDD by using BDD

Thanks!@cakper