Domain Driven Design Ryan Riley Catapult Systems, Inc.

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

.NET Database Technologies: Open-Source Frameworks.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
Craig Berntson
Ganesh Subramanian 22/12/2010
File Systems and Databases
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
Course Instructor: Aisha Azeem
RIZWAN REHMAN, CCS, DU. Advantages of ORDBMSs  The main advantages of extending the relational data model come from reuse and sharing.  Reuse comes.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
1 INTRODUCTION TO OOP Objective: Know the difference between functional programming and OOP Know basic terminology in OOP Know the importance of OOP Know.
Chapter 7: The Object-Oriented Approach to Requirements
Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.
Chapter 14: Object-Oriented Data Modeling
Page 1 ISMT E-120 Desktop Applications for Managers Introduction to Microsoft Access.
Why Analysis Process Refer to earlier chapters Models what the system will do makes it easier for understanding no environment considered (hence, system.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Chapter 6 System Engineering - Computer-based system - System engineering process - “Business process” engineering - Product engineering (Source: Pressman,
Domain-Driven Design using the ADO.NET Entity Framework Tim McCarthy Principal Engineer, InterKnowlogy
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
1/19 Component Design On-demand Learning Series Software Engineering of Web Application - Principles of Good Component Design Hunan University, Software.
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
Chris Hance. Why “Re-”evolving?  NIH Epidemic  My name is Chris, and I’m a… VB6 Coder  YAGNI.
Web Architecture & Services (2) Representational State Transfer (REST)
An Introduction to Software Architecture
Building an Offline Smart Client using Domain-Driven Design Principles Tim McCarthy.
Database Management System Prepared by Dr. Ahmed El-Ragal Reviewed & Presented By Mr. Mahmoud Rafeek Alfarra College Of Science & Technology Khan younis.
Detailed design – class design Domain Modeling SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.
1 Another group of Patterns Architectural Patterns.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Design engineering Vilnius The goal of design engineering is to produce a model that exhibits: firmness – a program should not have bugs that inhibit.
CSE 219 Computer Science III Program Design Principles.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 13 (Online): Object-Oriented Data Modeling Modern Database Management 10 th Edition.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
GRASP: Designing Objects with Responsibilities
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
Domain and Persistence Patterns. Fundamental Pattern Types Design Patterns Business Logic Patterns.
Applying Domain-Driven Design Jimmy Nilsson Webcast with UML China
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design, 2 nd Edition Copyright 2003 © John Wiley & Sons, Inc. All rights reserved.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Object-Oriented Data Modeling
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
SEA Side – Extreme Programming 1 SEA Side Software Engineering Annotations Architectural Patterns Professor Sara Stoecklin Director of Software Engineering-
Lecture 8&9 11/2/16 Introduction to OO Concepts 1.
From Use Cases to Implementation 1. Structural and Behavioral Aspects of Collaborations  Two aspects of Collaborations Structural – specifies the static.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
DOMAIN DRIVEN DESIGN Dave 12 May WHAT IS DDD? Set of principles to aid in building complex systems Enables us to focus on core problem domain NOT.
1 7 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 7 The Object-Oriented Approach to Requirements.
Domain Driven Design Day 2. DDD | Supple Design Inviting to change Reveals a deep model But … has no formula “… when complexity is holding back progress,
Class Design. Class Design The analysis phase determines what the implementation must do, and the system design.
From Use Cases to Implementation 1. Mapping Requirements Directly to Design and Code  For many, if not most, of our requirements it is relatively easy.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
CompSci 280 S Introduction to Software Development
Roberta Roth, Alan Dennis, and Barbara Haley Wixom
The Movement To Objects
MPCS – Advanced java Programming
Conception OBJET GRASP Patterns
Entity Framework By: Casey Griffin.
File Systems and Databases
Lec 3: Object-Oriented Data Modeling
Lecture 1: Multi-tier Architecture Overview
ARCH-1: Application Architecture made Simple
An Introduction to Software Architecture
Presentation transcript:

Domain Driven Design Ryan Riley Catapult Systems, Inc.

- Jak Charlton, Domain Driven Design Step-by-Step When you remember that DDD is really just “OO software done right”, it becomes more obvious that strong OO experience will also stand you in good stead when approaching DDD. - Jak Charlton, Domain Driven Design Step-by-Step

Agenda Conceptual Patterns Ubiquitous Language Entities Domain Driven Design Agenda Conceptual Ubiquitous Language Bounded Contexts Persistence Ignorance Refactoring Command Query Separation When to use DDD Patterns Entities Value Objects Aggregate Roots Object Creation Patterns Repository Specification Domain Services Modules Domain Events State Machines

Domain Driven Design Conceptual Elements (or what it means)

Domain Driven Design Domain First Focus on the Object Model Focus on Object-Oriented Design Works well with other *DD methods to: Reduce Complexity Increase Maintainability

Ubiquitous Language Model the language used by your domain experts Domain Driven Design Ubiquitous Language Model the language used by your domain experts Nouns == Classes Verbs == methods, services, etc. Example: A Hiring Specialist may post Jobs to the Job Board. Classes = Job, JobBoard Actions = JobBoard.PostJob(Job)

Bounded Contexts One of many integration patterns Domain Driven Design Bounded Contexts One of many integration patterns Continuous Integration Shared Kernel Customer / Supplier Conformist Anticorruption Layer Separate Ways More than One Ubiquitous Language Applicant terminology Hiring Specialist terminology Department terminology

Persistence Ignorance Domain Driven Design Persistence Ignorance Why is this important? Model-driven, not data-driven Focus on the domain, not the data structure Quickly swap out repositories for testing, POC, etc. How? Plain Old CLR Objects (POCO) Repository pattern (abstract the data access) Aggregate Roots More on this in a minute

Persistence Ignorance Domain Driven Design Persistence Ignorance UI Application / Service Domain Data Access Infrastructure

Refactoring “Refactor to deeper insights” Domain Driven Design Refactoring “Refactor to deeper insights” Include your domain experts in your refactoring Refactor your ubiquitous language 1st, your code 2nd This doesn’t mean refactor for greater reusability Example: benefit disbursements Initially used Retro disbursements for final partial-month payments Realized that these required different actions Symptom: confusion around the name Retro when talking about Final Partial Payments

Command Query Separation Domain Driven Design Command Query Separation User Interface Commands Query / Reporting Service Commands Domain Events Events Infrastructure Event Store

Command Query Separation Domain Driven Design Command Query Separation Origins – Eiffel language Use for Distributed architectures Move from class method level to the architectural level Separate Bounded Contexts for reading and writing Write == Commands == Change state and return nothing Read == Queries == Pure functions that do not change state Optimize each side differently Focus on: Event-Driven Architecture with Domain Events State Machines Allows easy transitions to: Messaging services Asynchronous processing Massive scalability

- Jak Charlton, Domain Driven Design Step-by-Step When to use DDD Now! (Not really) Fits approximately 5% of development project needs DDD is a software methodology suited to a particular kind of application – one where there is significant complexity, and there is a significant focus on a well defined business model. - Jak Charlton, Domain Driven Design Step-by-Step

Domain Driven Design Patterns (or how it works)

Dr. David West, Object Thinking Domain Driven Design Entities A behavioral approach mandates the assignment of responsibilities first. Only when you are satisfied with the distribution of responsibilities among your objects are you ready to make a decision about what they need to know…. Behavior is the only criterion we use to differentiate among objects. Dr. David West, Object Thinking When data is the center piece of your object, you assign data to objects before saying what they do. Descriptions of data don’t tell you squat about your objects. - Rocky Lhotka, http://www.theserverside.net/tt/articles/showarticle.tss?id=BusinessObjects

Entities, cont. The Domain Model pattern: Domain Driven Design Entities, cont. The Domain Model pattern: Structure Behavior No persistence behavior (i.e. Active Record) Uniquely identified and tracked Associated with other objects Simplify Remove unnecessary associations

Value Objects Nothing special (no identity) Domain Driven Design Value Objects Nothing special (no identity) Don’t confuse with value type Immutable One instance can be used for in multiple entities Examples: Money Address (usually) Codes

Aggregate Roots A complete and meaningful representation Domain Driven Design Aggregate Roots A complete and meaningful representation Based on a single root (Entity) Some entities or value objects don’t mean much alone Maintains state for a collection of objects Serves as a boundary between the objects inside and those outside Simplifies access to the associated objects The root has global identity and maintains invariants Aggregates may be nested Don’t go too deep! Examples: Job Board (Job) Job (Skill, Applicant) Applicant (Applicant Skill)

Object Creation Patterns Domain Driven Design Object Creation Patterns Aid in object creation Entities and Value Objects should ALWAYS be valid! Constructors Factory Simple Factory (Factory Method moved up to its own class) Factory Method (static method) Abstract Factory (composes from parts via inheritance) Builder Fluent Interfaces Example: String Builder Other Gang of Four patterns

Repository Abstraction over data access Domain Driven Design Repository Abstraction over data access Acts as a collection of Aggregate Roots Various approaches: Repository per Aggregate (very explicit) Generic Repository Repository per aggregate built upon Generic Repository Strategy Generic Repository with Specifications Used for querying and adding/removing Some implementations also add an Update Generally used along with a Unit of Work (e.g. DataContext)

Repository per Aggregate Domain Driven Design Repository per Aggregate Explicit query methods: GetById(int id) GetByName(string name) GetByCityAndState(City city, State state) AddApplicant(Applicant person) Pros: Very explicit and intentional interface so it reads better Restrict data access to what you want to allow developers Can more easily optimize each query Cons: Very manual process to create Cannot reuse methods for other purposes Extension requires editing the class

Generic Repository Generic, open query methods: Pros: Cons: Domain Driven Design Generic Repository Generic, open query methods: GetByKey<TKey>(TKey key) Query<T>(Expression<Func<T>> query) Insert<T>(T entity) Delete<T>(T entity) Update<T>(T entity) ? Pros: Very re-usable; write once, use everywhere Easy to code-gen for extension using partial classes More directly mimics database operations against a table Cons: Not intentional (Expressions?!) Little control over what happens on insert, delete, etc. Exposes methods you may not want exposed

Repository per Aggregate w/ Generic Strategy Domain Driven Design Repository per Aggregate w/ Generic Strategy Mix the best of both worlds: GetById(int id) : Query<Person>(p => p.Id == id) GetByName(string name) : Query<Person>(p => p.Name == name) Add(Person person) : Insert<Person>(person) Pros: Very explicit and intentional interface so it reads better Restrict data access to what you want to allow developers Can more easily optimize each query Standardize data access mechanics Simplify query construction in the repository Easier to swap out persistence technology (database / in-memory) Composition over Inheritance Cons: More code than Generic Repository More moving pieces

Generic Repository with Specifications Domain Driven Design Generic Repository with Specifications Generic functionality with explicit query functionality: Query<T>(ISpecification<T> specification) Add<T>(T entity) Pros: Extremely intention revealing Same reusability as Generic Repository Extend by creating new specifications Specifications can be used for more than querying (e.g. rules, etc.) Cons: Add, Remove, etc. may still be limited (but you probably shouldn’t do much else there anyway) May be difficult to tie into your ORM (ExpressionVisitor req’d for L2S or EF) What is a Specification?!

Specification Simple interface for defining criteria: Domain Driven Design Specification Simple interface for defining criteria: IsSatisfiedBy(T entity) Similar to the Query Object pattern Very intention revealing Very easy to test Easy to chain together for more complex queries: CompoiteSpecification: And, Or, Not LINQPad uses PredicateBuilder for a similar effect http://www.lostechies.com/blogs/chrismissal/archive/2009/09/10/using-the-specification-pattern-for-querying.aspx

Domain Services Do not confuse with Application Services Domain Driven Design Domain Services Do not confuse with Application Services Defining characteristics: Actions that do not fit within an entity or aggregate Stateless Examples: Transfers Calculators

Modules Break up your domain to reduce complexity Domain Driven Design Modules Break up your domain to reduce complexity Becomes part of the ubiquitous language Helps with decoupling Aids in extensibility

Domain Events (CQS) These are not delegate events POCO messages Domain Driven Design Domain Events (CQS) These are not delegate events POCO messages IPublish<TEvent> and IHandle<TEvent> Domain Models (Aggregates) publish events instead of saving to the database Eventual consistency (just like every other model)

Domain Driven Design State Machines (CQS) In CQS, you don’t change state, you publish changes State Machines: transition from one state to another Domain Model (Aggregate) defines transitions Examples: HTTP Stateless

Summary Useful for very difficult and complex domains Domain Driven Design Summary Useful for very difficult and complex domains Can help identify requirements Focus on the language Feel free to use patterns in other styles Add Command Query Separation for distributed systems

Domain Driven Design Questions?

Domain Driven Design Resources Books Domain Driven Design: Tackling Complexity in the Heart of Software Applying Domain Driven Design and Patterns Domain Driven Design Quickly (abbr. version of above) Domain Driven Design Step-by-Step ASP.NET MVC in Action Blogs Eric Evans Jimmy Nilsson Casey Charlton Greg Young (Distributed DDD/CQS)