software design trilogy part iii - domain driven design for ruby on rails applications

46

Upload: andymaleh

Post on 10-May-2015

5.797 views

Category:

Technology


0 download

DESCRIPTION

Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

TRANSCRIPT

Page 1: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications
Page 2: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

THE 80’S – RESPONSIBILITY DRIVEN DESIGN

Page 3: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

THE 90’S – DESIGN PATTERNS

Page 4: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

THE 2000’S – DOMAIN DRIVEN DESIGN

Page 5: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

WHAT WILL BE COVERED

•  Business Domain Modeling •  The Ubiquitous Language •  Model Driven Design •  Example Business Domain •  Demonstrative Rails Application

Page 6: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

WHAT WON’T BE COVERED

•  Refactoring Toward Deeper Insight •  Supple Design •  Large Scale Structure •  Bounded Contexts •  Distillation

Page 7: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

MUSIC SCHOOL BUSINESS

•  Offers classes for playing music, singing, and dancing •  Has a music instrument store that sells products •  Hosts music events with famous musicians •  Available in multiple locations

Page 8: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

EXAMPLE WEBSITE © Old Town School of Folk Music

Page 9: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

BUSINESS DOMAIN MODELING

•  Knowledge Crunching •  Continuous Learning •  Deeper Models

Page 10: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

KNOWLEDGE CRUNCHING

•  What types of classes do you offer? •  Do you offer the same classes in all locations? •  Do you sell anything other than music instruments? •  Are events paid for or free? •  How many classes does each instructor teach? •  How many lessons is a class? •  Do classes vary from session to session?

Page 11: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

CONTINUOUS LEARNING AND DEEPER MODELS

•  Instructors perform regularly at events •  Instructors provide series of classes •  Certain events recur regularly •  Music store offers location pick up service

Page 12: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

THE UBIQUITOUS LANGUAGE

•  Model Out Loud •  One Team, One Language •  Documents and Diagrams •  Executable Bedrock •  Explanatory Models

Page 13: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

MODEL OUT LOUD

•  Students register in a class with an instructor •  Students attend events •  Customers buy music products •  Instructors teach classes •  Locations offer classes

Page 14: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

ONE TEAM, ONE LANGUAGE

•  Course vs Class •  Student vs Customer •  Teacher vs Instructor •  Event vs Concert •  Location vs Branch

Page 15: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

DOCUMENTS

•  Top level goals •  Top level requirements •  Top level use cases

Page 16: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

DIAGRAMS

Customer Class

Location

Instructor

Event

Performer

Session

Class Series

Product

Page 17: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

EXECUTABLE BEDROCK AND EXPLANATORY MODELS •  Domain knowledge is apparent in code •  Method names describe behavior •  Class names map to actual business models

Page 18: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

MODEL DRIVEN DESIGN

•  Object Oriented Paradigm and Mixing Paradigms •  Layered Architecture •  Associations •  Entities •  Value Objects

Page 19: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

MODEL DRIVEN DESIGN

•  Services •  Modules •  Aggregates •  Factories •  Repositories

Page 20: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

OBJECT ORIENTED PARADIGM AND MIXING PARADIGMS •  Objects can generally embody any domain •  Certain domains can benefit from mixing paradigms: • Functional • Logic • Rule Engine

Page 21: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

LAYERED ARCHITECTURE

Page 22: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

ASSOCIATIONS

•  Unidirectional • Emphasizes natural bias for operation and domain logic • Communicates association better

•  Bidirectional • Multiple entry points for operation

Page 23: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

ASSOCIATIONS

•  Buying •  Enrollment •  Performing •  Location •  Timing

Page 24: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

ENTITIES

•  Have an identity independent of attributes •  Mutable •  Have a life cycle •  In Rails, typically handled with ActiveRecord •  When outgrowing ActiveRecord split into a separate

Ruby stateful class

Page 25: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

ENTITIES

•  Examples: • Customer •  Instructor • Class

Page 26: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

VALUE OBJECTS

•  Identified by their attribute values •  Immutable and unique •  In Rails, typically handled by pure Ruby objects •  Examples: • City • State • Class Name • Session Date Range

Page 27: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

AGGREGATES

•  Aggregate roots are entities aggregating other entities •  Manage the life cycle events of other entities •  Non-aggregates are discouraged from being accessed

directly to simply reasoning about the domain code •  In Rails, typically handled by ActiveRecord •  When outgrowing ActiveRecord, split off into a stateful

Ruby class and handle life-cycle hooks in an observer

Page 28: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

AGGREGATES

•  Examples: • ClassSeries aggregates Classes • Customer aggregates Address • Location aggregates Address

Page 29: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

FACTORIES

•  Handle creation of complex aggregate roots •  In Rails, typically handled by ActiveRecord •  When outgrowing ActiveRecord, split into a separete

Ruby stateless class

Page 30: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

FACTORIES

•  Examples: • ClassFactory handles creation of class with: • Session association • ClassCategory association •  Instructor association

Page 31: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

REPOSITORIES

• Handle storage and retrieval of aggregate roots • Manage lifecycle events •  In Rails, typically handled by ActiveRecord • When outgrowing ActiveRecord, split into a separate

stateless Ruby class that delegates work to ActiveRecord

Page 32: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

REPOSITORIES

• Examples: • StudentRepository •  InstructorRepository • SessionRepository

Page 33: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

SERVICES

•  Model stateless business processes without a lifecycle •  Useful for operations that span multiple entities •  Often represent use cases •  In Rails, typically represented in controllers that mix

view concerns •  When outgrowing Rails controllers, split into stateless

Ruby service objects

Page 34: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

SERVICES

•  Examples: • ClassEnrollmentService • MusicStoreService • EventTicketingService

Page 35: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

MODULES

•  Package cohesive units of business behavior •  Cut across software layers •  In Rails, handled with Modules and Rails Engines •  Examples: • MusicStore • ClassesEnrollment • EventTicketing

Page 36: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

RUBY ON RAILS APPLICATION

Page 37: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

RUBY ON RAILS APPLICATION

Page 38: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

RUBY ON RAILS APPLICATION

Page 39: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

RUBY ON RAILS APPLICATION

Page 40: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

RUBY ON RAILS APPLICATION

Page 41: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

RUBY ON RAILS APPLICATION

Page 42: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

WHAT WAS COVERED

•  Business Domain Modeling •  The Ubiquitous Language •  Model Driven Design •  Example Business Domain •  Demonstrative Rails Application

Page 43: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

QUESTIONS ???

Page 44: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

2010’S - ???

Page 45: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

REFERENCES

•  Domain-Driven Design by Eric Evans

Page 46: Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails Applications

CONTACT INFO

•  Andy Maleh / Software Engineer / Groupon •  Blog: http://andymaleh.blogspot.com •  Twitter: @AndyMaleh