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

Domain Driven Design

John Downey
September 26, 2011

Domain Driven Design

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  

    View full-size slide

  2. ¡  Domain  Driven  Design  
    by  Eric  Evans  
    ¡  Key  Concepts  
    §  Focus  on  the  business  
    domain  
    §  Work  with  Domain  
    Experts  
    §  Create  a  domain  model  
    §  Ubiquitous  language  

    View full-size slide

  3. ¡  Entities  
    ¡  Value  objects  
    ¡  Aggregates/Roots  
    ¡  Services  
    §  Repositories  
    §  Factories  
    ¡  Specifications  

    View full-size slide

  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  

    View full-size slide

  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  

    View full-size slide

  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  

    View full-size slide

  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  

    View full-size slide

  8. ¡  External  operations  
    §  Entities  
    §  Value  objects  
    ¡  No  state  
    ¡  Takes  place  of  static  
    methods  
    ¡  Specialized  
    implementations  
    §  Repositories  
    §  Factories  

    View full-size slide

  9. ¡  Responsible  for  
    persistence  
    ¡  Only  works  with  
    aggregate  roots  
    §  The  entire  aggregate  
    must  be  persisted  
    ¡  Typically  uses  a  
    database  to  save  state  

    View full-size slide

  10. ¡  Answers  a  yes/no  
    question  
    §  IsSatisfiedBy?  
    ¡  Used  when  multiple  
    roots  interact  
    ¡  Can  this  student  start  a  
    contract  for  Fall  2010?  

    View full-size slide

  11. ¡  Answers  questions  
    §  Reports  
    §  Complicated  lists  
    ¡  Low  level  query  
    ¡  Prevents  exponential  
    database  queries  
    ¡  Read-­‐only  objects  

    View full-size slide

  12. ¡  Overly  complicated  for  
    small  projects  
    ¡  Takes  time  
    ¡  Requires  domain  expert  
    ¡  Difficult  to  switch  gears  
    ¡  Complex  business  
    models  yield  complex  
    domain  models  

    View full-size slide

  13. ¡  Distributed  Domain  
    Driven  Design  (DDDD)  
    ¡  Command  Query  
    Responsibility  
    Segregation  (CQRS)  

    View full-size slide

  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/  

    View full-size slide