SlideShare una empresa de Scribd logo
1 de 79
Descargar para leer sin conexión
Domain-Driven Design
          A Collaboration Between
  Domain Experts and Software Practitioners
do·main
dōˈmān n.
a sphere of knowledge,
influence, or activity




      "domain." Merriam-Webster.com. 2011. http://www.merriam-webster.com/dictionary/domain (17 October 2011).
The Book




           http://domaindrivendesign.org/books/evans_2003
Training




           http://www.domainlanguage.com/
Complexity is in the domain,
not the technology
Models are tools used to
solve domain problems
The Model
A model is an abstract set of tools that is used to
solve problems within a domain

While represented in code, do not think of the
model as just code

Don’t try to model reality
from “The Story of Science: Power, Proof and Passion”, a 2010 BBC documentary
Ames Room
Used in The Lord Of The
Rings: The Fellowship of
the Ring to make the
hobbits appear the
correct size in relation
to Gandalf

We are always using
mental models to
understand the world
around us—we do not
perceive an objective
reality


                           By Alex Valavanis (own work) [public domain], via Wikimedia Commons
"Why I prefer Fahrenheit to Celsius [Fixed]." reddit. 2012.
http://www.reddit.com/r/funny/comments/wigk1/why_i_prefer_fahrenheit_to_celsius_fixed/ (16 September 2012).
“The map is not the territory.”
—Alfred Korzybski
This is not a pipe.


Magritte, René. The Treachery of Images (La trahision des images). 1929. Oil on canvas. Los Angeles County Museum of Art, Los Angeles, California.
"Everything simple is false. Everything
which is complex is unusable."
—Paul Valéry
Collaboratively explore the model
with both domain experts and
software practitioners
Case Study:
Three-Dimensional Animation
Software Practioner:
Edwin Catmull
Studied physics and computer science

Made many notable computer graphics discoveries

Eventually moved from two-dimensional to
three-dimensional animation

Hired by Lucasfilm to bring his expertise to the
entertainment field
Domain Expert:
John Lasseter
Studied animation and taught by veteran animators from Disney

Realized early-on the potential for computer generated imagery

Worked at, but eventually fired from, Disney

Hired by Edwin Catmull at Lucasfilm as an “Interface Designer”
because Catmull’s job didn’t include hiring animators[1]
                                                                                                                  [2]




          1. Buckley, A. M. "Chapter 3: Art Meets Science." Pixar: The Company and Its Founders. Edina, MN: ABDO, 2011. 27. Print.
          2. BSD Daemon Copyright 1988 by Marshall Kirk McKusick. All Rights Reserved. Drawn by John Lasseter.
“Throughout the process, Lasseter
worked side-by-side with the computer
scientists. Lasseter’s requests pushed
them to develop new tools, and their
feedback helped him learn the digital
animation process.”[1]



    1. Buckley, A. M. "Chapter 3: Art Meets Science." Pixar: The Company and Its Founders. Edina, MN: ABDO, 2011. 30. Print.
Identify your core domain
Core Domain
Identify your core domain

Distill your core domain

Focus your resources on the core domain
Distillation
Types of Domains
A model may represent:
  • your core domain
  • a supporting domain
  • a generic subdomain
Focus your modeling efforts on the core domain

Consider outsourcing work on supporting domains

Consider off-the-shelf software for generic subdomains
Identifying the Core Domain
Ask organizational leaders and domain experts:
  • What keeps you awake at night?
  • What makes your system worth writing?
  • Why not buy it off the shelf?
  • Why not outsource it?
There are always multiple models
Bounded Context
Delineates the applicability of a particular model

Bounded contexts allow each model to be explored in isolation

Clearly define:
  • Who is responsible for each bounded context
  • To which parts of the application is the bounded
    context applicable
  • What manifestations the bounded context will take
    (code, database schemas, etc.)
Ubiquitous Language
Speak a ubiquitous language within a bounded context

Terms must be clearly defined, unambiguous, and consistent

Critically important when communicating between
domain experts and software practitioners

The ubiquitous language will (and must) evolve as a progressively
richer understanding of the domain and the model are achieved

If the ubiquitous language cannot be used to clearly express
complex ideas, then you have more work to do!
Strategic Design
Context Map
Draw a context map of the current bounded contexts

Map what actually exists—not what you wish existed!

Identify relationships between contexts
Relationship Patterns
                   customer/            anticorruption
  partnership       supplier                 layer




shared kernel   big ball of         separate ways
                   mud




    open host          conformist           published
     service                                language
Building Blocks
Entity
Defined by a thread of continuity and identity

Only responsibilities should be around identity and life cycle

May be composed of other entities and/or value objects
Value Object
Defined by its encapsulated attributes

Treat value objects as immutable

Delegate business logic to value objects
Aggregate
A group of related entities and value objects

Useful when defining transaction, distribution,
and concurrency boundaries

A bounded context will have multiple aggregates
Aggregate Root
Designate one entity as the aggregate root

Allow external references to only the aggregate root

Persist the aggregate root, along with its object graph
Repository
Delegate persistence of an aggregate to a repository

A repository should behave as if it were an in-memory data store

Use an in-memory strategy for tests

If using an object-relational mapper (ORM):
Database -> ORM -> Repository
Service
A place for operations that aren’t naturally part of
any domain object

Like value objects, services should be treated as immutable

Operations on services are stateless
Model Exploration
Ubiquitous Language
Election Event
A set of Districts voting on a set of Ballot Items during the same
general period of time. Examples of Election Events include
primaries, general elections, and town meeting days.
Ballot Item
Either an Election or a Referendum as presented on a ballot.
Election
A formal decision-making process by which a population chooses
one or more Candidates to hold public office for a given District.
Election results may be tabulated based on Polling Place, Ward,
Municipality, or District. The winner or winners of an Election may
be determined by Plurality and/or a Winning Threshold.
District
A distinct territorial subdivision for holding separate Elections or
Referendums. A District may be a Municipality or a Ward, but this
is not always true. Districts are periodically redistricted, but are
immutable during a given Election Event. Districts can contain
sub-Districts (i.e. Polling Places, Wards, Municipalities, or other
Districts). A District’s sub-Districts may be different for different
Ballot Items.
Municipality
A District that can be a city, town, village, or other local
government unit.
Ward
An electoral District. Some Municipalities are comprised of
multiple Wards, some are not. In Vermont, only Burlington is
broken down by Ward. Note that for legislative Districts, only
parts of some Wards vote at a Polling Place. For example, the
Municipality of Burlington’s Ward 2 is broken into two or three
legislative house Districts.
Candidate
A person running for elected office. Write-ins are
considered Candidates.
Winning Threshold
A method of determining the winner of an Election, or the passing
of a Referendum, based on a minimum percentage (sometimes
plus one) of the total number of votes. This would sometimes be
combined with Plurality. For example, if an Election has a Winning
Threshold of 40% and two Candidates manage to both exceed
40%, then Plurality may be used to decide the winner. Some
examples of where Winning Threshold is used include:
  • Burlington Mayor: 40%
  • Revenue Bonds: 50%+1
  • GO Bonds: 66%
Scenario
Election for Burlington
City Councilor
The Town Meeting Day 2011 Election Event is under way. Ward 3
in the Municipality of Burlington is holding an Election for City
Councilor. This Election has three Candidates. It is 8:30pm and
Ward 3 has indicated the following results:
  • Vince Brennan (P) has 354 votes (60.2%)
  • Lynn Mesick (D) has 171 votes (29.1%)
  • Ron Ruloff (I) has 63 votes (10.7%)
This Election has a Winning Threshold of 40%, so Candidate Vince
Brennan (P) appears to be the winner.
Proposed Model
Warning: This proposed model is
intentionally flawed in order to
demonstrate opportunities for
further refinement.
Election Aggregate




                     http://yuml.me/b3094ce6
Election Entity
(Aggregate Root)
class Election implements BallotItem
{
    public function __construct($id) { }

    public function setElectionEvent(ElectionEvent $event) { }

    public function setDistrict(District $district) { }

    public function addCandidate(Candidate $candidate) { }

    /**
     * @return Candidate[]
     */
    public function getCandidates() { }
}
Candidate Entity
class Candidate
{
    public function __construct($id, Election $election) { }

    public function setVotes($count) { }

    public function getFractionOfVotes()
    {
        $totalVotes = 0;
        /* @var $candidate Candidate */
        foreach ($this->election->getCandidates() as $candidate) {
            $totalVotes += $candidate->votes;
        }
        return round($this->votes / $totalVotes, 3);
    }
Winning Policy Value Object
interface WinningPolicy
{
    /**
     * @return Candidate[]
     */
    public function determineWinners();
}
Winning Threshold
Value Object
class WinningThreshold implements WinningPolicy
{
    public function __construct($minimumPercentage, Election $election) { }

   /**
     * @return Candidate[]
     */
   public function determineWinners()
   {
        $winners = array();
        /* @var $candidate Candidate */
        foreach ($this->election->getCandidates() as $candidate) {
            if ($candidate->getFractionOfVotes() > $this->minimumPercentage) {
                $winners[] = $candidate;
            }
        }
        return $winners;
   }
Code Probe
Use concrete scenarios in discussions
with domain experts and in tests
Election Scenario
as Test
// The Town Meeting Day 2011 Election Event is under way.
$townMeetingDay2011 = new ElectionEvent('Town Meeting Day 2011');
// Ward 3 in the Municipality of Burlington…
$ward3 = new Ward('Ward 3');
$burlington = new Municipality('Burlington');
$ward3->setParentDistrict($burlington);
// …is holding an Election for City Councilor.
$cityCouncilor = new Election('City Councilor');
$cityCouncilor->setElectionEvent($townMeetingDay2011);
$cityCouncilor->setDistrict($ward3);
Election Scenario
as Test (cont’d)
// This Election has three Candidates.
$vinceBrennan = new Candidate(
    'Vince Brennan (P)',
    $cityCouncilor
);
$lynnMesick = new Candidate(
    'Lynn Mesick (D)',
    $cityCouncilor
);
$ronRuloff = new Candidate(
    'Ron Ruloff (I)',
     $cityCouncilor
);
Election Scenario
as Test (cont’d)
// It is 8:30pm and Ward 3 has indicated the following results:
$vinceBrennan->setVotes(354);
$lynnMesick->setVotes(171);
$ronRuloff->setVotes(63);
$this->assertEquals(.602, $vinceBrennan->getFractionOfVotes());
$this->assertEquals(.291, $lynnMesick->getFractionOfVotes());
$this->assertEquals(.107, $ronRuloff->getFractionOfVotes());
// This Election has a Winning Threshold of 40%…
$winningPolicy = new WinningThreshold(.40, $cityCouncilor);
// …so Candidate Vince Brennan (P) appears to be the winner.
$winners = $winningPolicy->determineWinners();
$this->assertContains($vinceBrennan, $winners);
$this->assertNotContains($lynnMesick, $winners);
$this->assertNotContains($ronRuloff, $winners);
Challenge the Model
Challenge Model
With More Scenarios
Questions to ask a domain expert:
 • What if two candidates reach the 40% winning threshold?
 • What if a candidate participates in two elections?
 • What about a municipality without wards?
 • How about an election that is won by plurality?
 • What’s different about referendums?
 • What changes when it’s a general election?
Supple Design
Closure of Operations
Have a method on a value object that returns an instance
of the same type of value object

Any method arguments should also be the same type as
the value object

Example: 2 + 3 = 5
  • “2” is a value object of type integer
  • integer has an add method
  • add method accepts an argument of type integer
  • add method returns an integer
  • integers are closed under the operation of addition
Totaling Ballot Item Results
class BallotItemResult
{
    /**
      * @param BallotItemResult[] $results
      * @return BallotItemResult
      */
    public function total(array $results)
    {
         /* @var $options BallotItemOption[] */
         $options = array();
         $votes = 0;
         /* @var $result BallotItemResult */
         foreach ($results as $result) {
             $options[] = $result->option;
             $votes += $result->votes;
         }
         $option = new CompositeBallotItemOption($options);
         return new BallotItemResult($option, $votes);
    }
}
Other Techniques
Intention-revealing interfaces
  • Is the method’s intention clear based on its interface?
Side-effect free functions
  • Does the method return a value and modify state?
  • Does the method interact with other objects and methods?
Assertions
  • What are the method’s preconditions?
  • What are the method’s postconditions?
Is the intention clear?
class BallotItemResult
{
    /**
     * Gets the fraction of votes for this Ballot Item Result
     * relative to the total number of votes for all Ballot
     * Item Results within the context Ballot Item
     *
     * @return float
     */
    public function getFractionOfVotes() { }
}
Side-Effect Free
class WinningThreshold implements WinningPolicy
{
   /**
      * @return Candidate[]
      */
    public function determineWinners()
    {
         $winners = array();
         /* @var $candidate Candidate */
         foreach ($this->election->getCandidates() as $candidate) {
             if ($candidate->getFractionOfVotes() > $this->minimumPercentage) {
                 $winners[] = $candidate;
             }
         }
         return $winners;
    }
}
Assert Preconditions
and Postconditions
public function determineWinners()
{
    assert($this->minimumPercentage >= 0);
    assert($this->minimumPercentage <= 1);
    $winners = array();
    /* @var $candidate Candidate */
    foreach ($this->election->getCandidates() as $candidate) {
        $fraction = $candidate->getFractionOfVotes();
        if ($fraction > $this->minimumPercentage) {
            $winners[] = $candidate;
        }
    }
    assert(count($winners) <= count($this->election->getCandidates()));
    return $winners;
}
Advanced Topics
Event Sourcing[1]




                    1. http://martinfowler.com/eaaDev/EventSourcing.html
Domain Event
Something important that happens within the domain
that may lead to a state change in a domain object

Domain events can trigger other domain events (e.g.
three strikes triggers an out)

Domain events are immutable
Event Log
Current state can be computed by reading the event log

Current state may be cached, if necessary for performance

Can also serve as an audit log
Command-Query Responsibility
Segregation (CQRS)
Write Model/Read Model
Define one model for writing data (commands)

Define another model for reading data (queries)

Both models operate on the same aggregate
http://oreilly.com/catalog/9781449303129/   http://oreilly.com/catalog/9781449303433/
Thank You
                                   @BradleyHolt
                              http://bradley-holt.com
                               https://joind.in/7025




Copyright © 2011-2012 Bradley Holt. All rights reserved.

Más contenido relacionado

Destacado

Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignNaeem Sarfraz
 
Code & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignCode & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignFrank Levering
 
Domain-driven design
Domain-driven designDomain-driven design
Domain-driven designKnoldus Inc.
 
A visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRSA visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRSLorenzo Nicora
 
Domain Driven Design and Hexagonal Architecture with Rails
Domain Driven Design and Hexagonal Architecture with RailsDomain Driven Design and Hexagonal Architecture with Rails
Domain Driven Design and Hexagonal Architecture with RailsDeclan Whelan
 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven DesignDavid Berliner
 
Why Domain-Driven Design Matters
Why Domain-Driven Design MattersWhy Domain-Driven Design Matters
Why Domain-Driven Design MattersMathias Verraes
 
Designing APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignDesigning APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignLaunchAny
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design IntroductionTung Nguyen Thanh
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCSteven Smith
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#Pascal Laurin
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slidesthinkddd
 
From C to Q one event at a time: Event Sourcing illustrated
From C to Q one event at a time: Event Sourcing illustratedFrom C to Q one event at a time: Event Sourcing illustrated
From C to Q one event at a time: Event Sourcing illustratedLorenzo Nicora
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignYoung-Ho Cho
 

Destacado (15)

Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
 
Code & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignCode & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven Design
 
Domain-driven design
Domain-driven designDomain-driven design
Domain-driven design
 
A visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRSA visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRS
 
Domain Driven Design and Hexagonal Architecture with Rails
Domain Driven Design and Hexagonal Architecture with RailsDomain Driven Design and Hexagonal Architecture with Rails
Domain Driven Design and Hexagonal Architecture with Rails
 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven Design
 
Why Domain-Driven Design Matters
Why Domain-Driven Design MattersWhy Domain-Driven Design Matters
Why Domain-Driven Design Matters
 
Designing APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignDesigning APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven Design
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVC
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slides
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
From C to Q one event at a time: Event Sourcing illustrated
From C to Q one event at a time: Event Sourcing illustratedFrom C to Q one event at a time: Event Sourcing illustrated
From C to Q one event at a time: Event Sourcing illustrated
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 

Similar a Domain-Driven Design at ZendCon 2012

Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven DesignBradley Holt
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsDebasish Ghosh
 
DITA's New Thang: Going Mapless!
DITA's New Thang: Going Mapless!DITA's New Thang: Going Mapless!
DITA's New Thang: Going Mapless!dclsocialmedia
 
Domain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsDomain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsHakka Labs
 
Demystifying Digital Humanities: Winter 2014 Workshop #2: Programming on the ...
Demystifying Digital Humanities: Winter 2014 Workshop #2: Programming on the ...Demystifying Digital Humanities: Winter 2014 Workshop #2: Programming on the ...
Demystifying Digital Humanities: Winter 2014 Workshop #2: Programming on the ...Paige Morgan
 
2013 Lecture 5: AR Tools and Interaction
2013 Lecture 5: AR Tools and Interaction 2013 Lecture 5: AR Tools and Interaction
2013 Lecture 5: AR Tools and Interaction Mark Billinghurst
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignMuhammad Ali
 
Dmdh winter 2015 session #2
Dmdh winter 2015 session #2Dmdh winter 2015 session #2
Dmdh winter 2015 session #2sarahkh12
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven DesignNicolò Pignatelli
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design QuicklyMariam Hakobyan
 
Interoperability defined by its reason d'être
Interoperability defined by its reason d'êtreInteroperability defined by its reason d'être
Interoperability defined by its reason d'êtreAALForum
 
Chatbots in 2017 -- Ithaca Talk Dec 6
Chatbots in 2017 -- Ithaca Talk Dec 6Chatbots in 2017 -- Ithaca Talk Dec 6
Chatbots in 2017 -- Ithaca Talk Dec 6Paul Houle
 
A Whirlwind Tour of Spatial Joins
A Whirlwind Tour of Spatial JoinsA Whirlwind Tour of Spatial Joins
A Whirlwind Tour of Spatial JoinsSafe Software
 
Successfully Kickstarting Data Governance's Social Dynamics: Define, Collabor...
Successfully Kickstarting Data Governance's Social Dynamics: Define, Collabor...Successfully Kickstarting Data Governance's Social Dynamics: Define, Collabor...
Successfully Kickstarting Data Governance's Social Dynamics: Define, Collabor...Stijn (Stan) Christiaens
 
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
Seminar - Scalable Enterprise Application Development Using DDD and CQRSSeminar - Scalable Enterprise Application Development Using DDD and CQRS
Seminar - Scalable Enterprise Application Development Using DDD and CQRSMizanur Sarker
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programmingAbzetdin Adamov
 
Refreshing Domain Driven Design
Refreshing Domain Driven DesignRefreshing Domain Driven Design
Refreshing Domain Driven DesignAndré Borgonovo
 
Deliverables that Clarify, Focus, and Improve Design
Deliverables that Clarify, Focus, and Improve DesignDeliverables that Clarify, Focus, and Improve Design
Deliverables that Clarify, Focus, and Improve DesignBen Peachey
 
D4U presentation 2 - coherency and consistency in domain models
D4U   presentation 2 - coherency and consistency in domain modelsD4U   presentation 2 - coherency and consistency in domain models
D4U presentation 2 - coherency and consistency in domain modelsPaul Valckenaers
 

Similar a Domain-Driven Design at ZendCon 2012 (20)

Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven Design
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain Models
 
DITA's New Thang: Going Mapless!
DITA's New Thang: Going Mapless!DITA's New Thang: Going Mapless!
DITA's New Thang: Going Mapless!
 
Domain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsDomain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron Edwards
 
Demystifying Digital Humanities: Winter 2014 Workshop #2: Programming on the ...
Demystifying Digital Humanities: Winter 2014 Workshop #2: Programming on the ...Demystifying Digital Humanities: Winter 2014 Workshop #2: Programming on the ...
Demystifying Digital Humanities: Winter 2014 Workshop #2: Programming on the ...
 
2013 Lecture 5: AR Tools and Interaction
2013 Lecture 5: AR Tools and Interaction 2013 Lecture 5: AR Tools and Interaction
2013 Lecture 5: AR Tools and Interaction
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Dmdh winter 2015 session #2
Dmdh winter 2015 session #2Dmdh winter 2015 session #2
Dmdh winter 2015 session #2
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven Design
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design Quickly
 
Interoperability defined by its reason d'être
Interoperability defined by its reason d'êtreInteroperability defined by its reason d'être
Interoperability defined by its reason d'être
 
Chatbots in 2017 -- Ithaca Talk Dec 6
Chatbots in 2017 -- Ithaca Talk Dec 6Chatbots in 2017 -- Ithaca Talk Dec 6
Chatbots in 2017 -- Ithaca Talk Dec 6
 
A Whirlwind Tour of Spatial Joins
A Whirlwind Tour of Spatial JoinsA Whirlwind Tour of Spatial Joins
A Whirlwind Tour of Spatial Joins
 
Successfully Kickstarting Data Governance's Social Dynamics: Define, Collabor...
Successfully Kickstarting Data Governance's Social Dynamics: Define, Collabor...Successfully Kickstarting Data Governance's Social Dynamics: Define, Collabor...
Successfully Kickstarting Data Governance's Social Dynamics: Define, Collabor...
 
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
Seminar - Scalable Enterprise Application Development Using DDD and CQRSSeminar - Scalable Enterprise Application Development Using DDD and CQRS
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
 
Eurolan 2005 Pedersen
Eurolan 2005 PedersenEurolan 2005 Pedersen
Eurolan 2005 Pedersen
 
Refreshing Domain Driven Design
Refreshing Domain Driven DesignRefreshing Domain Driven Design
Refreshing Domain Driven Design
 
Deliverables that Clarify, Focus, and Improve Design
Deliverables that Clarify, Focus, and Improve DesignDeliverables that Clarify, Focus, and Improve Design
Deliverables that Clarify, Focus, and Improve Design
 
D4U presentation 2 - coherency and consistency in domain models
D4U   presentation 2 - coherency and consistency in domain modelsD4U   presentation 2 - coherency and consistency in domain models
D4U presentation 2 - coherency and consistency in domain models
 

Más de Bradley Holt

Entity Relationships in a Document Database at CouchConf Boston
Entity Relationships in a Document Database at CouchConf BostonEntity Relationships in a Document Database at CouchConf Boston
Entity Relationships in a Document Database at CouchConf BostonBradley Holt
 
CouchConf NYC CouchApps
CouchConf NYC CouchAppsCouchConf NYC CouchApps
CouchConf NYC CouchAppsBradley Holt
 
ZendCon 2011 Learning CouchDB
ZendCon 2011 Learning CouchDBZendCon 2011 Learning CouchDB
ZendCon 2011 Learning CouchDBBradley Holt
 
jQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsjQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsBradley Holt
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBBradley Holt
 
Load Balancing with Apache
Load Balancing with ApacheLoad Balancing with Apache
Load Balancing with ApacheBradley Holt
 
CouchDB at New York PHP
CouchDB at New York PHPCouchDB at New York PHP
CouchDB at New York PHPBradley Holt
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3Bradley Holt
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web ServicesBradley Holt
 
Zend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughZend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughBradley Holt
 
Burlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBurlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBradley Holt
 

Más de Bradley Holt (14)

Entity Relationships in a Document Database at CouchConf Boston
Entity Relationships in a Document Database at CouchConf BostonEntity Relationships in a Document Database at CouchConf Boston
Entity Relationships in a Document Database at CouchConf Boston
 
CouchConf NYC CouchApps
CouchConf NYC CouchAppsCouchConf NYC CouchApps
CouchConf NYC CouchApps
 
ZendCon 2011 Learning CouchDB
ZendCon 2011 Learning CouchDBZendCon 2011 Learning CouchDB
ZendCon 2011 Learning CouchDB
 
jQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsjQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchApps
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDB
 
Load Balancing with Apache
Load Balancing with ApacheLoad Balancing with Apache
Load Balancing with Apache
 
CouchDB at New York PHP
CouchDB at New York PHPCouchDB at New York PHP
CouchDB at New York PHP
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
Zend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughZend Framework Quick Start Walkthrough
Zend Framework Quick Start Walkthrough
 
Burlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBurlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion Presentation
 

Último

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Último (20)

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Domain-Driven Design at ZendCon 2012

  • 1. Domain-Driven Design A Collaboration Between Domain Experts and Software Practitioners
  • 2. do·main dōˈmān n. a sphere of knowledge, influence, or activity "domain." Merriam-Webster.com. 2011. http://www.merriam-webster.com/dictionary/domain (17 October 2011).
  • 3. The Book http://domaindrivendesign.org/books/evans_2003
  • 4. Training http://www.domainlanguage.com/
  • 5. Complexity is in the domain, not the technology
  • 6. Models are tools used to solve domain problems
  • 7. The Model A model is an abstract set of tools that is used to solve problems within a domain While represented in code, do not think of the model as just code Don’t try to model reality
  • 8. from “The Story of Science: Power, Proof and Passion”, a 2010 BBC documentary
  • 9. Ames Room Used in The Lord Of The Rings: The Fellowship of the Ring to make the hobbits appear the correct size in relation to Gandalf We are always using mental models to understand the world around us—we do not perceive an objective reality By Alex Valavanis (own work) [public domain], via Wikimedia Commons
  • 10. "Why I prefer Fahrenheit to Celsius [Fixed]." reddit. 2012. http://www.reddit.com/r/funny/comments/wigk1/why_i_prefer_fahrenheit_to_celsius_fixed/ (16 September 2012).
  • 11. “The map is not the territory.” —Alfred Korzybski
  • 12. This is not a pipe. Magritte, René. The Treachery of Images (La trahision des images). 1929. Oil on canvas. Los Angeles County Museum of Art, Los Angeles, California.
  • 13.
  • 14. "Everything simple is false. Everything which is complex is unusable." —Paul Valéry
  • 15. Collaboratively explore the model with both domain experts and software practitioners
  • 17. Software Practioner: Edwin Catmull Studied physics and computer science Made many notable computer graphics discoveries Eventually moved from two-dimensional to three-dimensional animation Hired by Lucasfilm to bring his expertise to the entertainment field
  • 18. Domain Expert: John Lasseter Studied animation and taught by veteran animators from Disney Realized early-on the potential for computer generated imagery Worked at, but eventually fired from, Disney Hired by Edwin Catmull at Lucasfilm as an “Interface Designer” because Catmull’s job didn’t include hiring animators[1] [2] 1. Buckley, A. M. "Chapter 3: Art Meets Science." Pixar: The Company and Its Founders. Edina, MN: ABDO, 2011. 27. Print. 2. BSD Daemon Copyright 1988 by Marshall Kirk McKusick. All Rights Reserved. Drawn by John Lasseter.
  • 19. “Throughout the process, Lasseter worked side-by-side with the computer scientists. Lasseter’s requests pushed them to develop new tools, and their feedback helped him learn the digital animation process.”[1] 1. Buckley, A. M. "Chapter 3: Art Meets Science." Pixar: The Company and Its Founders. Edina, MN: ABDO, 2011. 30. Print.
  • 21. Core Domain Identify your core domain Distill your core domain Focus your resources on the core domain
  • 23. Types of Domains A model may represent: • your core domain • a supporting domain • a generic subdomain Focus your modeling efforts on the core domain Consider outsourcing work on supporting domains Consider off-the-shelf software for generic subdomains
  • 24. Identifying the Core Domain Ask organizational leaders and domain experts: • What keeps you awake at night? • What makes your system worth writing? • Why not buy it off the shelf? • Why not outsource it?
  • 25. There are always multiple models
  • 26. Bounded Context Delineates the applicability of a particular model Bounded contexts allow each model to be explored in isolation Clearly define: • Who is responsible for each bounded context • To which parts of the application is the bounded context applicable • What manifestations the bounded context will take (code, database schemas, etc.)
  • 27. Ubiquitous Language Speak a ubiquitous language within a bounded context Terms must be clearly defined, unambiguous, and consistent Critically important when communicating between domain experts and software practitioners The ubiquitous language will (and must) evolve as a progressively richer understanding of the domain and the model are achieved If the ubiquitous language cannot be used to clearly express complex ideas, then you have more work to do!
  • 29. Context Map Draw a context map of the current bounded contexts Map what actually exists—not what you wish existed! Identify relationships between contexts
  • 30. Relationship Patterns customer/ anticorruption partnership supplier layer shared kernel big ball of separate ways mud open host conformist published service language
  • 32. Entity Defined by a thread of continuity and identity Only responsibilities should be around identity and life cycle May be composed of other entities and/or value objects
  • 33. Value Object Defined by its encapsulated attributes Treat value objects as immutable Delegate business logic to value objects
  • 34. Aggregate A group of related entities and value objects Useful when defining transaction, distribution, and concurrency boundaries A bounded context will have multiple aggregates
  • 35. Aggregate Root Designate one entity as the aggregate root Allow external references to only the aggregate root Persist the aggregate root, along with its object graph
  • 36. Repository Delegate persistence of an aggregate to a repository A repository should behave as if it were an in-memory data store Use an in-memory strategy for tests If using an object-relational mapper (ORM): Database -> ORM -> Repository
  • 37. Service A place for operations that aren’t naturally part of any domain object Like value objects, services should be treated as immutable Operations on services are stateless
  • 39.
  • 41. Election Event A set of Districts voting on a set of Ballot Items during the same general period of time. Examples of Election Events include primaries, general elections, and town meeting days.
  • 42. Ballot Item Either an Election or a Referendum as presented on a ballot.
  • 43. Election A formal decision-making process by which a population chooses one or more Candidates to hold public office for a given District. Election results may be tabulated based on Polling Place, Ward, Municipality, or District. The winner or winners of an Election may be determined by Plurality and/or a Winning Threshold.
  • 44. District A distinct territorial subdivision for holding separate Elections or Referendums. A District may be a Municipality or a Ward, but this is not always true. Districts are periodically redistricted, but are immutable during a given Election Event. Districts can contain sub-Districts (i.e. Polling Places, Wards, Municipalities, or other Districts). A District’s sub-Districts may be different for different Ballot Items.
  • 45. Municipality A District that can be a city, town, village, or other local government unit.
  • 46. Ward An electoral District. Some Municipalities are comprised of multiple Wards, some are not. In Vermont, only Burlington is broken down by Ward. Note that for legislative Districts, only parts of some Wards vote at a Polling Place. For example, the Municipality of Burlington’s Ward 2 is broken into two or three legislative house Districts.
  • 47. Candidate A person running for elected office. Write-ins are considered Candidates.
  • 48. Winning Threshold A method of determining the winner of an Election, or the passing of a Referendum, based on a minimum percentage (sometimes plus one) of the total number of votes. This would sometimes be combined with Plurality. For example, if an Election has a Winning Threshold of 40% and two Candidates manage to both exceed 40%, then Plurality may be used to decide the winner. Some examples of where Winning Threshold is used include: • Burlington Mayor: 40% • Revenue Bonds: 50%+1 • GO Bonds: 66%
  • 50. Election for Burlington City Councilor The Town Meeting Day 2011 Election Event is under way. Ward 3 in the Municipality of Burlington is holding an Election for City Councilor. This Election has three Candidates. It is 8:30pm and Ward 3 has indicated the following results: • Vince Brennan (P) has 354 votes (60.2%) • Lynn Mesick (D) has 171 votes (29.1%) • Ron Ruloff (I) has 63 votes (10.7%) This Election has a Winning Threshold of 40%, so Candidate Vince Brennan (P) appears to be the winner.
  • 52. Warning: This proposed model is intentionally flawed in order to demonstrate opportunities for further refinement.
  • 53. Election Aggregate http://yuml.me/b3094ce6
  • 54. Election Entity (Aggregate Root) class Election implements BallotItem { public function __construct($id) { } public function setElectionEvent(ElectionEvent $event) { } public function setDistrict(District $district) { } public function addCandidate(Candidate $candidate) { } /** * @return Candidate[] */ public function getCandidates() { } }
  • 55. Candidate Entity class Candidate { public function __construct($id, Election $election) { } public function setVotes($count) { } public function getFractionOfVotes() { $totalVotes = 0; /* @var $candidate Candidate */ foreach ($this->election->getCandidates() as $candidate) { $totalVotes += $candidate->votes; } return round($this->votes / $totalVotes, 3); }
  • 56. Winning Policy Value Object interface WinningPolicy { /** * @return Candidate[] */ public function determineWinners(); }
  • 57. Winning Threshold Value Object class WinningThreshold implements WinningPolicy { public function __construct($minimumPercentage, Election $election) { } /** * @return Candidate[] */ public function determineWinners() { $winners = array(); /* @var $candidate Candidate */ foreach ($this->election->getCandidates() as $candidate) { if ($candidate->getFractionOfVotes() > $this->minimumPercentage) { $winners[] = $candidate; } } return $winners; }
  • 59. Use concrete scenarios in discussions with domain experts and in tests
  • 60. Election Scenario as Test // The Town Meeting Day 2011 Election Event is under way. $townMeetingDay2011 = new ElectionEvent('Town Meeting Day 2011'); // Ward 3 in the Municipality of Burlington… $ward3 = new Ward('Ward 3'); $burlington = new Municipality('Burlington'); $ward3->setParentDistrict($burlington); // …is holding an Election for City Councilor. $cityCouncilor = new Election('City Councilor'); $cityCouncilor->setElectionEvent($townMeetingDay2011); $cityCouncilor->setDistrict($ward3);
  • 61. Election Scenario as Test (cont’d) // This Election has three Candidates. $vinceBrennan = new Candidate( 'Vince Brennan (P)', $cityCouncilor ); $lynnMesick = new Candidate( 'Lynn Mesick (D)', $cityCouncilor ); $ronRuloff = new Candidate( 'Ron Ruloff (I)', $cityCouncilor );
  • 62. Election Scenario as Test (cont’d) // It is 8:30pm and Ward 3 has indicated the following results: $vinceBrennan->setVotes(354); $lynnMesick->setVotes(171); $ronRuloff->setVotes(63); $this->assertEquals(.602, $vinceBrennan->getFractionOfVotes()); $this->assertEquals(.291, $lynnMesick->getFractionOfVotes()); $this->assertEquals(.107, $ronRuloff->getFractionOfVotes()); // This Election has a Winning Threshold of 40%… $winningPolicy = new WinningThreshold(.40, $cityCouncilor); // …so Candidate Vince Brennan (P) appears to be the winner. $winners = $winningPolicy->determineWinners(); $this->assertContains($vinceBrennan, $winners); $this->assertNotContains($lynnMesick, $winners); $this->assertNotContains($ronRuloff, $winners);
  • 64. Challenge Model With More Scenarios Questions to ask a domain expert: • What if two candidates reach the 40% winning threshold? • What if a candidate participates in two elections? • What about a municipality without wards? • How about an election that is won by plurality? • What’s different about referendums? • What changes when it’s a general election?
  • 66. Closure of Operations Have a method on a value object that returns an instance of the same type of value object Any method arguments should also be the same type as the value object Example: 2 + 3 = 5 • “2” is a value object of type integer • integer has an add method • add method accepts an argument of type integer • add method returns an integer • integers are closed under the operation of addition
  • 67. Totaling Ballot Item Results class BallotItemResult { /** * @param BallotItemResult[] $results * @return BallotItemResult */ public function total(array $results) { /* @var $options BallotItemOption[] */ $options = array(); $votes = 0; /* @var $result BallotItemResult */ foreach ($results as $result) { $options[] = $result->option; $votes += $result->votes; } $option = new CompositeBallotItemOption($options); return new BallotItemResult($option, $votes); } }
  • 68. Other Techniques Intention-revealing interfaces • Is the method’s intention clear based on its interface? Side-effect free functions • Does the method return a value and modify state? • Does the method interact with other objects and methods? Assertions • What are the method’s preconditions? • What are the method’s postconditions?
  • 69. Is the intention clear? class BallotItemResult { /** * Gets the fraction of votes for this Ballot Item Result * relative to the total number of votes for all Ballot * Item Results within the context Ballot Item * * @return float */ public function getFractionOfVotes() { } }
  • 70. Side-Effect Free class WinningThreshold implements WinningPolicy { /** * @return Candidate[] */ public function determineWinners() { $winners = array(); /* @var $candidate Candidate */ foreach ($this->election->getCandidates() as $candidate) { if ($candidate->getFractionOfVotes() > $this->minimumPercentage) { $winners[] = $candidate; } } return $winners; } }
  • 71. Assert Preconditions and Postconditions public function determineWinners() { assert($this->minimumPercentage >= 0); assert($this->minimumPercentage <= 1); $winners = array(); /* @var $candidate Candidate */ foreach ($this->election->getCandidates() as $candidate) { $fraction = $candidate->getFractionOfVotes(); if ($fraction > $this->minimumPercentage) { $winners[] = $candidate; } } assert(count($winners) <= count($this->election->getCandidates())); return $winners; }
  • 73. Event Sourcing[1] 1. http://martinfowler.com/eaaDev/EventSourcing.html
  • 74. Domain Event Something important that happens within the domain that may lead to a state change in a domain object Domain events can trigger other domain events (e.g. three strikes triggers an out) Domain events are immutable
  • 75. Event Log Current state can be computed by reading the event log Current state may be cached, if necessary for performance Can also serve as an audit log
  • 77. Write Model/Read Model Define one model for writing data (commands) Define another model for reading data (queries) Both models operate on the same aggregate
  • 78. http://oreilly.com/catalog/9781449303129/ http://oreilly.com/catalog/9781449303433/
  • 79. Thank You @BradleyHolt http://bradley-holt.com https://joind.in/7025 Copyright © 2011-2012 Bradley Holt. All rights reserved.