Thinking in DDD
Improve Your Software Without Being a Guru
Thinking in DDD Improve Your Software Without Being a Guru - - PowerPoint PPT Presentation
Thinking in DDD Improve Your Software Without Being a Guru Domain-Driven Design is a large topic and becoming an expert is a goal that involves years of experience. But DDD provides so many wonderful and powerful ideas that you can learn
Improve Your Software Without Being a Guru
Domain-Driven Design is a large topic and becoming an expert is a goal that involves years of experience. But DDD provides so many wonderful – and powerful – ideas that you can learn from and benefit from right away when designing or refactoring software. In this half-day workshop, based on extensive real-word experience, you will learn about some of the DDD patterns such as bounded contexts, aggregates, anti-corruption layers as well as the importance of thinking about your database persistence as a cross-cutting concern. You will also gain some insight into modeling domains and learn how to continue questioning your processes until the "aha!" moment arrives to you and your development team. With these important tools you can already begin to improve your software design and maintainability as well as your sanity. And with these tools in hand you can continue to explore, practice and be guided by additional techniques that come from Domain-Driven Design.
Write Code
History of success with complex projects Principles & patterns to solve difficult problems Clear, testable code that represents the domain Aligns with practices from that come from years of experience
It’s all about
the
Interaction With Domain Experts Model a single Sub-Domain at a time
Manage Employees Marketing Accounting Purchase Materials Sales Engineering
Interaction With Domain Experts Model a single Sub-Domain at a time Implementation
Sub-Domains
a
Software implementation Modeling Communication Development Process
Time and Effort
Discuss & model the problem with domain expert Isolate domain logic from other parts of application
Learning curve (why you’re watching this course)
New principles New patterns New processes
Only makes sense when there is complexity in the problem
Not just CRUD or data-driven applications Not just technical complexity without business domain complexity
Team or Company Buy-In to DDD
Software implementation
BOUNDED CONTEXT UBIQUITOUS LANGUAGE AGGREGATES
Modeling Communication
ANTI- CORRUPTION LAYER VALUE OBJECTS
MODEL- DRIVEN DESIGN
ENTITIES
a
bit.ly/PS-DDD
2003 2006 2013
2014
are your
But Where Is the Database?
But Where Is the Database?
Cross-Cutting Concerns
Identify Bounded Contexts for software to manage this business organization What Behaviors are in these contexts?
Anti-Corruption Layers
Creative Commons http://commons.wikimedia.org/wiki/File:Cosplay_of_superheroes.jpg
Bo Bounded Co Context Bo Bounded Co Context Le Legacy Ap App Insulate Bounded Contexts
between
using
Design patterns, e.g. : Façade, Adapter
Even when the other system is well designed, it is not based on the same model as the client.
—Eric Evans
Domain-Driven Design
And often the other system is not well designed.
The structure of an Anti-Corruption Layer
Source: Evans, Domain-Driven Design, p. 367
“Customer”
public class Customer{ }
“Customer Registers”
private Customer (string Name, Date regDate){} public static Register (string Name, Date regDate){ return new Customer(name,regDate);
Ubiquitous Language
For a single Bounded Context Used throughout that context, from conversations to code
Recognize that a change in the ubiquitous language is a change in the model.
—Eric Evans
Product Component
Product Aggregate
N 1
AGGREGATES
Ag Aggregates in in the Na Navigation Map
Evans, Domain-Driven Design, p. 65
Schedule an appointment for a checkup Note a pet’s weight Request lab work Notify pet owner of vaccinations due Accept a new patient Book a room
Appointment.Time Pet.Name Owner.Telephone Room.Number
Select some of the bounded contexts Within that B.C. what entities belong together in an aggregate? What is the aggregate root? Why?
Domain Models
Domain Models
Rich for DDD Anemic for CRUD
private private
ENTITIES
Entities in the Navigation Map
Evans, Domain-Driven Design, p. 65
Entities in the Appointment Scheduling Context
A bidirectional association means that both objects can be understood only together. When application requirements do not call for traversal in both directions, adding a traversal direction reduces interdependence and simplifies the design.
—Eric Evans
Doctor Appointment Client Patient Patient Client
VALUE OBJECTS
ü Measures, quantifies, or describes a thing in the domain. ü Identity is based on composition of values ü Immutable ü Compared using all values ü No side effects
“Boots” lives with Pluralsight author, Lars Klint
Company Worth: $50,000,000
$ 50,000,000
Company (Entity) ID (guid): 9F63CE8D-9F1E-45E0-85AB-C098CC15F8E6 Worth Unit (string): “Canadian Dollar” Worth Amount (decimal): 50000000
Worth (Value Object) Monetary Unit (string) “Canadian Dollar” Amount (decimal): 50000000 Company (Entity) ID (guid): 9F63CE8D-9F1E-45E0-85AB-C098CC15F8E6 Worth{
Source:http://fit.c2.com/wiki.cgi?WholeValue(Ward Cunningham)
public class DateTimeRange { public DateTimeRange(DateTime start, DateTime end) { Start=start; End=end; } public DateTime Start { get; private set; } public DateTime End { get; private set; } … }
Patient Appointment
10:00 am Jan 4, 2014 – 11:00 am Jan 4, 2014
Staff Meeting
2:00 pm Feb 1, 2014 – 3:15 pm Feb 1, 2014
It may surprise you to learn that we should strive to model using Value Objects instead of Entities wherever possible. Even when a domain concept must be modeled as an Entity, the Entity’s design should be biased toward serving as a value container rather than a child Entity container.
—Vaughn Vernon
Implementing Domain Driven Design
Pick same Bounded Context you used for aggregate root What behaviors need to happen within there Can you justify 1:1 relationships or are they better as value objects? Can you justify bi-directional relationshps or are they better as uni-directional Model some of the methods
§ Domain-Driven Design Fundamentals on Pluralsight bit.ly/PS-DDD § All of my Pluralsight courses: pluralsight.com/author/julie-lerman § Domain-Driven Design, Eric Evans amzn.to/1kstiRg § Implementing Domain-Driven Design, Vaughn Vernon amzn.to/1dgYRY3 § Domain Modeling with Entity Framework Scorecard, Jimmy Bogard, bit.ly/1x925bu § Coding for Domain-Driven Design: Tips for Data-Focused Devs (3 Parts)
MSDN Magazine, Aug, Sept& Oct 2013 bit.ly/15xMlDL
§ CQRS Journey from MS Patterns & Practices: bit.ly/cqrsjourney § A Pattern for Sharing Data Across Domain-Driven Design Bounded Contexts (Part 1&2)
MSDN Magazine, Oct & Dec 2014: bit.ly/DataPoints_Dec2014
§ Entity Framework Model Partitioning in Domain-Driven Design Bounded Contexts
TechEd Europe 2014: bit.ly/TEE2014_EFDDD