Kansas City Developer Conference 2011 Domain Driven Design Implementation Patterns and Considerations in.NET.

Slides:



Advertisements
Similar presentations
January 30, 2014 Copyright Jim Farley Beyond JDBC: Java Object- Relational Mappings Jim Farley e-Commerce Program Manager GE Research and Development
Advertisements

Architecture-based Evolution of Software Systems José Luiz Fiadeiro Architecture-based Evolution of Software Systems Luís Andrade João Gouveia Georgios.
And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering.
St Louis Day of.NET 2011 Refactoring to a SOLID Foundation Steve Bohlen Senior Software Engineer SpringSource/VMware Blog:
Columbia, Maryland - Summer 2011 Introduction to Agile Principles, Practices, and Processes Steve Bohlen Senior Software Engineer SpringSource/VMware.
Data Model driven applications using CASE Data Models as the nucleus of software development in a Computer Aided Software Engineering environment.
St Louis Day of.NET 2011 Taming Dependency Chaos with Inversion of Control Containers Steve Bohlen Senior Software Engineer SpringSource/VMware
Fabian Vilers Hands on ASP.NET MVC.
Craig Berntson
Building Enterprise Applications Using Visual Studio ®.NET Enterprise Architect.
Chapter 6: Using Design Patterns
Ganesh Subramanian 22/12/2010
Design Patterns CS is not simply about programming
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Kansas City Developer Conference 2011 Unit Testing Patterns and Anti-Patterns Steve Bohlen Blog:
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
St Louis Day of.NET 2011 Unit Testing Patterns and Anti-Patterns Steve Bohlen Senior Software Engineer SpringSource/VMware Blog:
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Computational Thinking Related Efforts. CS Principles – Big Ideas  Computing is a creative human activity that engenders innovation and promotes exploration.
By Bob Bunson  Simulation of software development project  Fictitious system from Concept to Code  Oriented around the.
Objektorienteret netværkskommunikation Presentation: Architectures for Distributed Systems.
Domain Driven Design Implementation Patterns and Considerations in.NET.
Daniel Levy Solutions Consultant, Telerik Testing Tools Division.
Entity Framework Code First End to End
Presenter - Donn Felker.  Senior Consultant for Microsoft Gold Certified Partner- Statêra.  8 years of experience in developing and architecting enterprise.
Chapter 6 System Engineering - Computer-based system - System engineering process - “Business process” engineering - Product engineering (Source: Pressman,
Introduction to “Oslo” Jeremy Boyd Director – Mindscape MSDN Regional Director
Domain-Driven Design using the ADO.NET Entity Framework Tim McCarthy Principal Engineer, InterKnowlogy
Todd Snyder Development Team Lead Infragistics Experience Design Group.
Domain-Driven Design Tim McCarthy Principal Engineer, InterKnowlogy
Building an Offline Smart Client using Domain-Driven Design Principles Tim McCarthy.
RECALL THE MAIN COMPONENTS OF KIM Functional User Interfaces We just looked at these Reference Implementation We will talk about these later Service Interface.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
1 Another group of Patterns Architectural Patterns.
Design Patterns: Structural Design Patterns
A Novel Approach to Architectural Recovery in Evolving Object- Oriented Systems PhD thesis Koen De Hondt December 11, 1998.
Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 10 Use Case Design.
Inversion Of Control & Dependency Injection Break Apart The Dependencies Oren Eini Senior Developer We! Consulting Group
Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC.
Alcatel-Lucent CDC Workshop, Coaching & Knowledge Transfer Architecture.
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
Applying Domain-Driven Design Jimmy Nilsson Webcast with UML China
Core Indigo Patterns Ted Neward
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Domain Model Classes and Objects Association Structure Requirement Specification Domain Model.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Building State of the art presentation tiers Nauzad Kapadia
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Domain-Driven Design for the Database-Driven Mind
The Data Access Object Pattern (Structural – Not a GoF Pattern) ©SoftMoore ConsultingSlide 1.
SEA Side – Extreme Programming 1 SEA Side Software Engineering Annotations Architectural Patterns Professor Sara Stoecklin Director of Software Engineering-
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
CS223: Software Engineering
Introduction  “M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
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.
A Web Service Software Factory Introduction Don Smith Product Manager patterns & practices.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Building Enterprise Applications Using Visual Studio®
Chapter 5:Design Patterns
Domain Driven Design basic concepts and best practises
ADO.NET Entity Framework Marcus Tillett
ADO.NET Entity Framework
Data Access in Your Code Thinking Outside the Framework
Telerik Testing Framework
Presentation transcript:

Kansas City Developer Conference 2011 Domain Driven Design Implementation Patterns and Considerations in.NET

We want to thank the sponsors of KCDC. Without them, none of this would be possible. Thanks to Our Sponsors Product Sponsors Silver Sponsors Gold Sponsors

Kansas City Developer Conference 2011 Do I suck? Let me (and the world) know!

Kansas City Developer Conference 2011 Who am I? …and why should you care? Steve Bohlen I Read Books + Write Software vs. “Read Software + Write Books” Blog, Screencast, Speak, Share, Learn

Kansas City Developer Conference 2011 Steve Bohlen Nearly 20 years developing software LISP, Delphi, C/C++, VB, VB.NET, C# Senior Engineer Springsource/VMware Co-Founder, NYC Alt.Net User Group Co-Organizer, NYC DDD User Group Contributor: various OSS projects NHibernate NDbUnit Spring.NET blog:

Kansas City Developer Conference 2011 RAD Controls for ASP.NET AJAX RAD Controls for Silverlight RAD Controls for Windows Phone RAD Controls for Winforms RAD Controls for WPF Telerik Reporting Telerik OpenAccess ORM Telerik JustCode Telerik JustMock Telerik Extensions for ASP.NET MVC Test Studio Express Telerik TeamPulse Telerik Test Studio Sitefinity CMS Telerik JustDecopile C#/VB.NET Converter ASPX to Razor Converter

Kansas City Developer Conference

Kansas City Developer Conference

Kansas City Developer Conference

Kansas City Developer Conference 2011 Beta Presentation

Kansas City Developer Conference 2011 Opinions Ahead

Kansas City Developer Conference 2011 Agenda Concepts Behind DDD (as needed) Implementation Patterns and Concerns for DDD Model Building Blocks in C# General DDD Coding Anti-Patterns Domain Entities Domain Value Objects Domain Repositories Domain Services Domain Validation Discussion

Kansas City Developer Conference 2011 Exploring DDD Concepts

Kansas City Developer Conference 2011 The Role of Patterns in Software Once: it’s a fluke, twice: its coincidence, three times: it’s a pattern Discovered (observed), not Invented – Except for their name Elevate effectiveness of our communication – A ‘shorthand’ for more complex ideas Only effective if we all agree on the semantic meaning of the elements of the Pattern Language!

Kansas City Developer Conference 2011 Software Pattern Language Hierarchy Solution Design Software Architecture Software Construction GOF Design Patterns Fowler POEAA Evans DDD

Kansas City Developer Conference 2011 DDD: The Premise Writing software is actually straightforward Determining what to write is hard! The Key to success is understanding the Problem Domain intimately The words we choose to express concepts matter and convey rich meaning

Kansas City Developer Conference 2011 Ubiquitous Language Developers and Business People move in different worlds – Different languages to express our ideas F R I C T I O N ! ! ! What if we all spoke the same language? – Our common language would be…ubiquitous

Kansas City Developer Conference 2011 Ubiquitous Language Used everywhere – classes, methods, variables, etc. Even in Tests – Behavior-Driven Development! Conversing using the language enables… – ‘Solution smells’ detected by Domain Experts – Discovery of new domain concepts by developers – Shared learning by all involved

Kansas City Developer Conference 2011 DDD: Organizing Strategies Aggregate Roots Bounded Contexts Context Maps Anti-Corruption Layers

Kansas City Developer Conference 2011 DDD: Aggregate Root ‘Parent Entity’ Controls all access to children objects Simplifies interaction with complex object graphs ‘Gateway’ to richer objects

Kansas City Developer Conference 2011 Semantic Meaning is all about Context DDD: Bounded Contexts

Kansas City Developer Conference 2011 DDD: Context Maps When we need to communicate across Bounded Contexts Translation of ideas Not always bi- directional

Kansas City Developer Conference 2011 DDD: Anti-Corruption Layers Protect your self from the Big Ball of Mud! Isolate the parts of your system that change from the parts that are stable!

Kansas City Developer Conference 2011 DDD: Model Building Blocks

Kansas City Developer Conference 2011 DDD: Organizing Strategies

Kansas City Developer Conference 2011 DDD: Model Building Blocks Entities Value Objects Repositories Services Validation

Kansas City Developer Conference 2011 Entities

Kansas City Developer Conference 2011 Coding DDD Entities Distilled Identity Equality – Objects are just reference-equal by default in.NET – Equals, GetHashCode, IEquatable Identity Comparison Control of Access to Children Objects within the aggregate – Customer.AddOrder(theOrder);, Customer.RemoveOrder(theOrder); – Not Customer.Orders.Add(theOrder); Infrastructure-Ignorant – Persistent-Ignorant, UI-Ignorant, etc.

Kansas City Developer Conference 2011 Challenges with DDD Entities Do we expose Identity value as a property? – Isn’t that a persistence-concern? – Providing a setter means the ‘identity’ of my entity can be changed by something external to it (bad!) Are General Property Setters/Getters a smell? – Means your domain is trending towards DTO-hell – Entities as property-containers for data – Non-Meaningful names for things!

Kansas City Developer Conference 2011 Exploring Entities in Code

Kansas City Developer Conference 2011 Value Objects

Kansas City Developer Conference 2011 public class Customer { public int Id { get; set;} public string Firstname {get; set;} public string Lastname {get; set;} public int BuildingNumber {get; set;} public string Street {get; set;} public string City {get; set;} public string State {get; set;} public string PostalCode {get; set;} } public class Customer { public int Id { get; set;} public string Firstname {get; set;} public string Lastname {get; set;} public int BuildingNumber {get; set;} public string Street {get; set;} public string City {get; set;} public string State {get; set;} public string PostalCode {get; set;} } DDD: Entities and Value Objects public class Name { public string Firstname {get; set;} public string Lastname {get; set;} } public class Name { public string Firstname {get; set;} public string Lastname {get; set;} } public class Customer { public int Id { get; set;} public Name FullName {get; set;} public Address ShippingAddress {get; set;} public Address BillingAddress {get; set;} } public class Customer { public int Id { get; set;} public Name FullName {get; set;} public Address ShippingAddress {get; set;} public Address BillingAddress {get; set;} } public class Address { public int BuildingNumber {get; set;} public string Street {get; set;} public string City {get; set;} public string State {get; set;} public string PostalCode {get; set;} } public class Address { public int BuildingNumber {get; set;} public string Street {get; set;} public string City {get; set;} public string State {get; set;} public string PostalCode {get; set;} }

Kansas City Developer Conference 2011 Coding DDD Value Objects Distilled Immutable – After construction, no changes to the object – Read-Only Properties Value-Equality – Equals, GetHashCode, IEquatable Property-by-Property comparison!

Kansas City Developer Conference 2011 Challenges with DDD Value Objects Tedious to write boilerplate IEquatable implementation code by hand every time If immutable, how do we modify one? – Not entirely a trick question If no identity, how do we persist them???? – Deconstruction into basic data types?

Kansas City Developer Conference 2011 Exploring Value Objects in Code

Kansas City Developer Conference 2011 Repositories

Kansas City Developer Conference 2011 Coding DDD Repositories Distilled Domain Model not tied to specific Persistence Abstract the act of query/retrieval Do so in a Domain-Centric Way – ( CustomerRepository.GetById(int id) is NOT domain-centric!) This is a data-access-layer suffixed with ’ Repository ’!

Kansas City Developer Conference 2011 Challenges with DDD Repositories If no persistence in the Domain Model, how do we reference repositories in there? –A–Abstraction/indirection Repository Boundary blurring –O–OK for query constructs to come from outside? repos.GetBySpecification(Specification spec); –O–OK for Specification to be tied to implementation? repos.GetByCriteria(DetachedCriteria crit); –O–OK for lazy-executed queries to be returned? public IQueryable<Customer> GetCustomers() Guarding against Repository API-bloat –T–The repository is dead, long live the repository!

Kansas City Developer Conference 2011 Exploring Repositories in Code

Kansas City Developer Conference 2011 Services

Kansas City Developer Conference 2011 Coding DDD Services Distilled Actions/Behaviors not belonging in Entities Injected into Entities (?) Operating Autonomously from Entities

Kansas City Developer Conference 2011 Challenges with DDD Services Is having Services just to inject into Entities an anti-pattern? Order order = new Order(taxservice); double cost = Order.TotalWithTax(); If Services coordinate Entity interaction, who new s-up the service? Having all behavior expressed in Services and none in Entities is an anti-pattern –O–Or is it? And why?

Kansas City Developer Conference 2011 Exploring Services in Code

Kansas City Developer Conference 2011 Validation

Kansas City Developer Conference 2011 Coding DDD Validation Distilled Validation is often a stand-in for ‘business rules’ –b–bool CanShipOrder(); Distinguish between persistence validation and business action validation –R–Rarely the same thing! Entity Validation –E–Entities can be valid for some things and invalid for others Place an order (if valid customer w/ a valid account) Ship an Order (if valid account and under credit limit) Value Object Validation –P–Prevent VO from entering an invalid state in the first place!

Kansas City Developer Conference 2011 Challenges with DDD Validation Validation without ‘for what?’ is pointless –b–bool IsValid(); //??? Validation Frameworks tend to assume validation means persistence –D–Does NOT mean cannot be repurposed for Domain Validation! Where does validation happen if it requires collaboration between multiple Entities? –b–bool order.CanShipTo(customer); –b–bool customer.CanShip(order); –b–bool shippingValidator.CanShip(customer, order) –A–Anemic Domain Model Anti-Pattern?

Kansas City Developer Conference 2011 Exploring Validation in Code

Kansas City Developer Conference 2011 Common DDD Coding Anti-Patterns DDD Constructs with ‘type-suffixes’ ‘Types’ are ‘roles’ in the Domain Model Not… CustomerEntity AddressValueObject CustomerRepository ShippingService OverdueOrderSpecification Repository as glorified DAL repository.Get(int id) repository.Save(Customer c) repository.Delete(Customer c) repository.Update(Customer c)

Kansas City Developer Conference 2011 Common DDD Anti-Patterns Anemic Domain Model – The DTO pattern Exposed DAOs – Repository ‘leakage’ into the domain ‘Fat’ Service Layer Separation of Data and Behavior Technical terms sneak into the Domain Model – Slightly-less-than-ubiquitous-language

Kansas City Developer Conference 2011 Some Criticisms of DDD Jeremy Miller: “Jargon Explosion” – Aggregates, Entities, Value Objects, Bounded Contexts, Anti-Corruption Layers, Oh My! – Singleton, Observer, State, Strategy, Adapter, Bridge, Facade Rob Conery: “Bland, Generic Terms” – Singleton, Observer, State, Strategy, Adapter, Bridge, Facade

Kansas City Developer Conference 2011 Discussion Viewpoints Experiences Values Domain Language – More Discussion: – – Domaindrivendesign /