Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Domain-Driven Design          A Collaboration Between  Domain Experts and Software Practitioners
The Book           http://domaindrivendesign.org/books/evans_2003
Training           http://www.domainlanguage.com/
do·maindōˈmān n.a sphere of knowledge,influence, or activity      "domain." Merriam-Webster.com. 2011. http://www.merriam-...
Complexity is in the domain,not the technology
Case Study: Election Reporting
Elections vs. ReferendumsElections and referendums are not as similar asthey at first appearElection winners may be determ...
Local vs. Statewide ElectionsTown Meeting Day (March) elections are very different thanstatewide elections (November)During...
DistrictsSome districts may contain only part of a municipality or wardThe Chittenden-3-6 Vermont Representative District ...
Let technology playa supporting role
Models are tools used tosolve domain problems
Ames RoomUsed in The Lord Of TheRings: The Fellowship ofthe Ring to make thehobbits appear thecorrect size in relationto G...
"Why I prefer Fahrenheit to Celsius [Fixed]." reddit. 2012.http://www.reddit.com/r/funny/comments/wigk1/why_i_prefer_fahre...
Collaboratively explore the modelwith both domain experts andsoftware practitioners
Case Study:Three-Dimensional Animation
Software Practioner:Edwin CatmullStudied physics and computer scienceMade many notable computer graphics discoveriesEventu...
Domain Expert:John LasseterStudied animation and taught by veteran animators from DisneyRealized early-on the potential fo...
“Throughout the process, Lasseterworked side-by-side with the computerscientists. Lasseter’s requests pushedthem to develo...
Identify your core domain
Core DomainIdentify your core domainDistill your core domainFocus your resources on the core domain
Collaboratively exploredomain models
The ModelA model is an abstract set of tools that is used tosolve problems within a domainWhile represented in code, do no...
“The map is not the territory.”—Alfred Korzybski
Magritte, René. The Treachery of Images (La trahision des images). 1929. Oil on canvas. Los Angeles County Museum of Art, ...
This is not a pipe.Magritte, René. The Treachery of Images (La trahision des images). 1929. Oil on canvas. Los Angeles Cou...
"Everything simple is false. Everythingwhich is complex is unusable."—Paul Valéry
There are always multiple models
Bounded ContextDelineates the applicability of a particular modelBounded contexts allow each model to be explored in isola...
Ubiquitous LanguageSpeak a ubiquitous language within a bounded contextTerms must be clearly defined, unambiguous, and con...
Exploring the Model
A Model Exploration ProcessAsk a domain expert to tell you a story (the scenario)Propose a modelCode the scenario using un...
Use concrete scenarios in discussionswith domain experts and in unit tests
Building Blocks
EntityDefined by a thread of continuity and identityOnly responsibilities should be around identity and life cycleMay be c...
Value ObjectDefined by its encapsulated attributesTreat value objects as immutableDelegate business logic to value objects
Defining an object as an entity or avalue object is context-dependent
AggregateA group of related entities and value objectsUseful when defining transaction, distributionand concurrency bounda...
Aggregate RootDesignate one entity as the aggregate rootAllow external references to only the aggregate rootUse unidirecti...
RepositoryDelegate persistence of an aggregate root to a repositoryA repository should behave as if it were an in-memory d...
ServiceA place for operations that aren’t naturally part ofany domain objectLike value objects, services should be immutab...
Command-Query ResponsibilitySegregation (CQRS)
Commands & QueriesCommands are responsible for changing stateQueries are responsible for retrieving stateA commands may de...
Write Model/Read ModelDefine one model for writing data (commands)Define another model for reading data (queries)Both mode...
Event Sourcing[1]                    1. http://martinfowler.com/eaaDev/EventSourcing.html
Domain EventSomething important that happens within the domainthat may lead to a state change in a domain objectDomain eve...
Event LogCurrent state can be computed by reading the event logRetroactive events can be used to “fix” application stateCu...
Supple Design
Closure of OperationsHave a method on a value object that returns an instanceof the same type of value objectAny method ar...
Other TechniquesIntention-revealing interfacesSide-effect free functionsAssertions
Strategic Design
Context MapDraw a context map of the current bounded contextsMap what actually exists—not what you wish existed!Identify r...
Relationship Patterns                   customer/            anticorruption  partnership       supplier                 la...
Distillation
Types of DomainsA model my represent:  • your core domain  • a supporting domain  • a generic subdomainFocus your modeling...
Identifying the Core DomainAsk organizational leaders and domain experts:  • What keeps you awake at night?  • What makes ...
Don’t settle on not havingaccess to a domain expert!
http://oreilly.com/catalog/9781449303129/   http://oreilly.com/catalog/9781449303433/
Thank You                                   @BradleyHolt                              http://bradley-holt.comCopyright © 2...
Domain-Driven Design
Domain-Driven Design
Upcoming SlideShare
Loading in …5
×

Domain-Driven Design

1,853 views

Published on

Domain-driven design is a collaborative process involving both domain experts and software practitioners that attempts to address issues of complexity in software. This process is described in the book Domain-Driven Design written by Eric Evans. Domain-driven design starts with the assertion that complexity is in the domain, not in the technology. Accordingly, we must let technology play a supporting role.

A person practicing domain-driven design does not attempt to model reality. Instead, domain experts and software practitioners use a mental model as a tool for solving problems within a given domain. The domain experts and software practitioners collaborate to explore and develop this model. We will look at the concept of a bounded context within which models can be isolated and explored. We will talk about domain-driven design's building block patterns including entities, value objects, aggregates, repositories, services, and domain events. We will see how test-driven development can be used as a means of exploring the model.

Published in: Technology, Business
  • Be the first to comment

Domain-Driven Design

  1. 1. Domain-Driven Design A Collaboration Between Domain Experts and Software Practitioners
  2. 2. The Book http://domaindrivendesign.org/books/evans_2003
  3. 3. Training http://www.domainlanguage.com/
  4. 4. do·maindōˈ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).
  5. 5. Complexity is in the domain,not the technology
  6. 6. Case Study: Election Reporting
  7. 7. Elections vs. ReferendumsElections and referendums are not as similar asthey at first appearElection winners may be determined by pluralityand/or winning thresholdReferendums can only be passed by meeting awinning threshold
  8. 8. Local vs. Statewide ElectionsTown Meeting Day (March) elections are very different thanstatewide elections (November)During statewide elections, voters may be voting in both local andstatewide elections at the same time—each with different districtboundariesDistrict boundaries dictate reporting needs—statewide electionsneed to be reported one way, local elections another
  9. 9. DistrictsSome districts may contain only part of a municipality or wardThe Chittenden-3-6 Vermont Representative District contains allof Winooski and part of Burlington’s Ward 1Citizens in this part of Burlington’s Ward 1 vote in Winooski forstatewide elections and in Burlington for local electionsAudience expects both aggregate and detailed reportingRedistricting can occur between elections
  10. 10. Let technology playa supporting role
  11. 11. Models are tools used tosolve domain problems
  12. 12. Ames RoomUsed in The Lord Of TheRings: The Fellowship ofthe Ring to make thehobbits appear thecorrect size in relationto GandalfWe are always usingmental models tounderstand the worldaround us—we do notperceive an objectivereality By Alex Valavanis (own work) [public domain], via Wikimedia Commons
  13. 13. "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).
  14. 14. Collaboratively explore the modelwith both domain experts andsoftware practitioners
  15. 15. Case Study:Three-Dimensional Animation
  16. 16. Software Practioner:Edwin CatmullStudied physics and computer scienceMade many notable computer graphics discoveriesEventually moved from two-dimensional tothree-dimensional animationHired by Lucasfilm to bring his expertise to theentertainment field
  17. 17. Domain Expert:John LasseterStudied animation and taught by veteran animators from DisneyRealized early-on the potential for computer generated imageryWorked at, but eventually fired from, DisneyHired by Edwin Catmull at Lucasfilm as an “Interface Designer”because Catmull’s job didn’t include hiring animators[1] 1. Buckley, A. M. "Chapter 3: Art Meets Science." Pixar: The Company and Its Founders. Edina, MN: ABDO, 2011. 27. Print.
  18. 18. “Throughout the process, Lasseterworked side-by-side with the computerscientists. Lasseter’s requests pushedthem to develop new tools, and theirfeedback helped him learn the digitalanimation process.”[1] 1. Buckley, A. M. "Chapter 3: Art Meets Science." Pixar: The Company and Its Founders. Edina, MN: ABDO, 2011. 30. Print.
  19. 19. Identify your core domain
  20. 20. Core DomainIdentify your core domainDistill your core domainFocus your resources on the core domain
  21. 21. Collaboratively exploredomain models
  22. 22. The ModelA model is an abstract set of tools that is used tosolve problems within a domainWhile represented in code, do not think of themodel as just codeA “real world model” is a fool’s errandThe model must be explored collaboratively withdomain experts and software practitioners
  23. 23. “The map is not the territory.”—Alfred Korzybski
  24. 24. Magritte, René. The Treachery of Images (La trahision des images). 1929. Oil on canvas. Los Angeles County Museum of Art, Los Angeles, California.
  25. 25. 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.
  26. 26. "Everything simple is false. Everythingwhich is complex is unusable."—Paul Valéry
  27. 27. There are always multiple models
  28. 28. Bounded ContextDelineates the applicability of a particular modelBounded contexts allow each model to be explored in isolationClearly 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.)Document the interactions between bounded contextswith a context map
  29. 29. Ubiquitous LanguageSpeak a ubiquitous language within a bounded contextTerms must be clearly defined, unambiguous, and consistentCritically important when communicating betweendomain experts and software practitionersThe ubiquitous language will (and must) evolve as a progressivelyricher understanding of the domain and the model are achievedIf the ubiquitous language cannot be used to clearly expresscomplex ideas, then you have more work to do!
  30. 30. Exploring the Model
  31. 31. A Model Exploration ProcessAsk a domain expert to tell you a story (the scenario)Propose a modelCode the scenario using unit testsRepeat
  32. 32. Use concrete scenarios in discussionswith domain experts and in unit tests
  33. 33. Building Blocks
  34. 34. EntityDefined by a thread of continuity and identityOnly responsibilities should be around identity and life cycleMay be composed of other entities and/or value objects
  35. 35. Value ObjectDefined by its encapsulated attributesTreat value objects as immutableDelegate business logic to value objects
  36. 36. Defining an object as an entity or avalue object is context-dependent
  37. 37. AggregateA group of related entities and value objectsUseful when defining transaction, distributionand concurrency boundariesA model will likely have multiple aggregates
  38. 38. Aggregate RootDesignate one entity as the aggregate rootAllow external references to only the aggregate rootUse unidirectional references within an aggregate rootfor less complexity • Example: Reference a line item’s order, or an order’s line items, but not bothMaintain references on the “many” side of a “one-to-many”relationships for less complexity: • Example: Reference a line item’s order, rather than an order’s line items
  39. 39. RepositoryDelegate persistence of an aggregate root to a repositoryA repository should behave as if it were an in-memory data storeIf using an object-relational mapper (ORM):Database -> ORM -> RepositoryUse an in-memory strategy for unit testsStraddles persistence and domain layers, allowing you tostay focused on the domain model
  40. 40. ServiceA place for operations that aren’t naturally part ofany domain objectLike value objects, services should be immutableOperations on services are stateless
  41. 41. Command-Query ResponsibilitySegregation (CQRS)
  42. 42. Commands & QueriesCommands are responsible for changing stateQueries are responsible for retrieving stateA commands may delegate the actual state changeto a domain event
  43. 43. Write Model/Read ModelDefine one model for writing data (commands)Define another model for reading data (queries)Both models will likely share aggregate root entity identifiers
  44. 44. Event Sourcing[1] 1. http://martinfowler.com/eaaDev/EventSourcing.html
  45. 45. Domain EventSomething important that happens within the domainthat may lead to a state change in a domain objectDomain events can trigger other domain events (e.g.three strikes triggers an out)Domain events are immutableTypically stored in an event log
  46. 46. Event LogCurrent state can be computed by reading the event logRetroactive events can be used to “fix” application stateCurrent state may be cached, if necessary for performanceCan also serve as an audit log
  47. 47. Supple Design
  48. 48. Closure of OperationsHave a method on a value object that returns an instanceof the same type of value objectAny method arguments should also be the same type asthe value objectExample: 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
  49. 49. Other TechniquesIntention-revealing interfacesSide-effect free functionsAssertions
  50. 50. Strategic Design
  51. 51. Context MapDraw a context map of the current bounded contextsMap what actually exists—not what you wish existed!Identify relationships between contexts
  52. 52. Relationship Patterns customer/ anticorruption partnership supplier layershared kernel big ball of separate ways mud open host conformist published service language
  53. 53. Distillation
  54. 54. Types of DomainsA model my represent: • your core domain • a supporting domain • a generic subdomainFocus your modeling efforts on the core domainConsider outsourcing work on supporting domainsConsider off-the-shelf software for generic subdomains
  55. 55. Identifying the Core DomainAsk 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?
  56. 56. Don’t settle on not havingaccess to a domain expert!
  57. 57. http://oreilly.com/catalog/9781449303129/ http://oreilly.com/catalog/9781449303433/
  58. 58. Thank You @BradleyHolt http://bradley-holt.comCopyright © 2011-2012 Bradley Holt. All rights reserved.

×