Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Domain Driven Design

Avatar for John Downey John Downey
September 26, 2011

Domain Driven Design

Avatar for John Downey

John Downey

September 26, 2011
Tweet

More Decks by John Downey

Other Decks in Programming

Transcript

  1. ¡  Anti-­‐pattern   ¡  Logic  outside  the   model  

    ¡  Copy/paste   programming   ¡  Recurring  bugs  
  2. ¡  Domain  Driven  Design   by  Eric  Evans   ¡ 

    Key  Concepts   §  Focus  on  the  business   domain   §  Work  with  Domain   Experts   §  Create  a  domain  model   §  Ubiquitous  language  
  3. ¡  Entities   ¡  Value  objects   ¡  Aggregates/Roots  

    ¡  Services   §  Repositories   §  Factories   ¡  Specifications  
  4. ¡  Immutable  (System.String)   §  Can  only  be  constructed,  never

     changed   §  Methods  and  properties  can’t  change  state   §  Modifications  return  new  object   §  Safer  especially  in  multi-­‐threaded  environments   ¡  Mutable  (System.Text.StringBuilder)   §  Methods  and  properties  can  change  state   §  Can  be  faster  in  practice  
  5. ¡  Has  an  identity   (PersonID)   ¡  Equality  is

     based  on  this   identity   ¡  Conceptually  immutable   §  Except  through  public   methods   §  Protects  from  invalid   states   Person   PersonID   Puid   Name   Email   This  is  my  entity,  there  are  many  like  it,  but  this  one  is  mine  
  6. ¡  Has  no  concept  of   identity   §  Equality

     is  based  on   identical  state   ¡  Should  be  truly   immutable   Color   Red   Green   Blue   Alpha   I  see  a  red  door  and  I  want  it  painted  black  
  7. ¡  Brings  related  entities/ values  together   §  Under  one

     entity   ¡  Guarantee  consistency   ¡  Outside  entities  can   only  reference  a  root   ¡  Controls  the  entire   aggregate   Order   OrderLines   Money   Address   Referral   OrderType  
  8. ¡  External  operations   §  Entities   §  Value  objects

      ¡  No  state   ¡  Takes  place  of  static   methods   ¡  Specialized   implementations   §  Repositories   §  Factories  
  9. ¡  Responsible  for   persistence   ¡  Only  works  with

      aggregate  roots   §  The  entire  aggregate   must  be  persisted   ¡  Typically  uses  a   database  to  save  state  
  10. ¡  Answers  a  yes/no   question   §  IsSatisfiedBy?  

    ¡  Used  when  multiple   roots  interact   ¡  Can  this  student  start  a   contract  for  Fall  2010?  
  11. ¡  Answers  questions   §  Reports   §  Complicated  lists

      ¡  Low  level  query   ¡  Prevents  exponential   database  queries   ¡  Read-­‐only  objects  
  12. ¡  Overly  complicated  for   small  projects   ¡  Takes

     time   ¡  Requires  domain  expert   ¡  Difficult  to  switch  gears   ¡  Complex  business   models  yield  complex   domain  models  
  13. ¡  Distributed  Domain   Driven  Design  (DDDD)   ¡  Command

     Query   Responsibility   Segregation  (CQRS)  
  14. ¡  Free  eBooks   §  http://thinkddd.com/   §  http://www.infoq.com/minibooks/domain-­‐driven-­‐ design-­‐quickly

      ¡  Websites   §  http://www.domaindrivendesign.org/   §  http://stackoverflow.com/questions/tagged/ddd   §  http://elegantcode.com/