building an offline smart client using domain-driven design principles

37
http://www.umlchina.com Building an Offline Smart Client using Domain- Driven Design Principles Tim McCarthy

Upload: gomer

Post on 13-Jan-2016

18 views

Category:

Documents


0 download

DESCRIPTION

Building an Offline Smart Client using Domain-Driven Design Principles. Tim McCarthy. Agenda. DDD Definitions/Patterns The SmartCA Application Designing the Layered Architecture WPF and the Model-View-ViewModel Pattern Synchronizing the Data. Agenda. DDD Definitions/Patterns - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Building an Offline Smart Client using Domain-Driven Design Principles

http://www.umlchina.com

Building an Offline Smart Client using Domain-Driven Design Principles

Tim McCarthy

Page 2: Building an Offline Smart Client using Domain-Driven Design Principles

Agenda

1. DDD Definitions/Patterns

2. The SmartCA Application

3. Designing the Layered Architecture

4. WPF and the Model-View-ViewModel Pattern

5. Synchronizing the Data

Page 3: Building an Offline Smart Client using Domain-Driven Design Principles

Agenda

1. DDD Definitions/Patterns

2. The SmartCA Application

3. Designing the Layered Architecture

4. WPF and the Model-View-ViewModel Pattern

5. Synchronizing the Data

Page 4: Building an Offline Smart Client using Domain-Driven Design Principles

What is Domain-Driven Design (DDD)?

Sponsor Logo

Page 5: Building an Offline Smart Client using Domain-Driven Design Principles

Why Domain-Driven Design (DDD)?

Most development time is still spent writing plumbing code instead of business logic

Typically, the UI will change a LOT more than the business logic

The model is a great tool for communication between developers and users

.NET has good support for it!

Page 6: Building an Offline Smart Client using Domain-Driven Design Principles

Ubiquitous Language

Common terms between business experts and development team

Use the language in your codeNamespacesClass, property, method, variable names

Page 7: Building an Offline Smart Client using Domain-Driven Design Principles

Communicating the Language

Create whiteboard drawingsFavor whiteboarding over VisioUse digital camera to capture, then paste into

Word

Use Visual Studio class diagrams for core parts of the domainCode and diagram are kept in syncNo wasted time diagramming, your diagram is

the code

Page 8: Building an Offline Smart Client using Domain-Driven Design Principles

Definition: Entities

An object defined primarily by its identityNot its attributes

Could be a person, a customer, an order, etc.

Not all objects have meaningful identities…

In some systems, a class may be an ENTITY, in others maybe not

Page 9: Building an Offline Smart Client using Domain-Driven Design Principles

Definition: Value Objects

Represent an aspect of the domain with NO conceptual identity

Use when you care about what something is, not who they are

Same thing as a DTO [Fowler PoEAA]Simple, immutable objects

Page 10: Building an Offline Smart Client using Domain-Driven Design Principles

Definition: Aggregates

A cluster of associated objects treated as a unit for the purpose of data changes

They have a root and a boundaryBoundary = what is inside the AGGREGATERoot = single ENTITY inside the

AGGREGATE

Hardest but most important concept to understand in DDD!

Page 11: Building an Offline Smart Client using Domain-Driven Design Principles

Aggregate Rules

The root ENTITY has global identityENTITIES inside the boundary have local

identityNothing outside the AGGREGATE

boundary can hold a reference to anything inside, except to the root ENTITY

Objects in the AGGREGATE can hold references to other AGGREGATE roots

…a few more

Page 12: Building an Offline Smart Client using Domain-Driven Design Principles

Definition: Services

An operation offered as an interface that stands alone in the model

Does not fit into any of the objects in the model

StatelessTo be used judiciously (do not turn your

app into a Transaction Script)Use when an operation is an important

domain concept

Page 13: Building an Offline Smart Client using Domain-Driven Design Principles

Pattern: Layered Supertype [Fowler 475]

Type that acts as the supertype for all types in its layer, i.e. a base class!

Factors out common features, such as handling the identity of ENTITIESExample: a common Id property

Helps eliminate duplicate code

Page 14: Building an Offline Smart Client using Domain-Driven Design Principles

Pattern: Repository

Provide access to AGGREGATE rootsRepresents all objects of a certain type as

a conceptual set (usually emulated)Behaves like a collection, e.g. Add(),

Remove(), FindBy(id), etc.Persistence Ignorance!

Page 15: Building an Offline Smart Client using Domain-Driven Design Principles

Pattern: Layered Architecture

Page 16: Building an Offline Smart Client using Domain-Driven Design Principles

Agenda

1. DDD Definitions/Patterns

2. The SmartCA Application

3. Designing the Layered Architecture

4. WPF and the Model-View-ViewModel Pattern

5. Synchronizing the Data

Page 17: Building an Offline Smart Client using Domain-Driven Design Principles

The SmartCA Application

Problem – Legacy MS Access Applicationa.k.a. Smart Client Anti-Pattern

New System RequirementsTechnologiesLayered Architecture

Page 18: Building an Offline Smart Client using Domain-Driven Design Principles

The Legacy Application

Page 19: Building an Offline Smart Client using Domain-Driven Design Principles

New System Requirements

Reliability and AvailabilityScalabilityMaintainabilityRich client application functionalityOffline Capable Intelligent installation and auto-update

functionalityAdditional client device support

Page 20: Building an Offline Smart Client using Domain-Driven Design Principles

The New Solution – SmartCA Application

DDD with Layered Architecture UI = WPF Smart ClientData Store

Server – behind web services cloudClient – SQL Server Compact Edition 3.5

Page 21: Building an Offline Smart Client using Domain-Driven Design Principles

Agenda

1. DDD Definitions/Patterns

2. The SmartCA Application

3. Designing the Layered Architecture

4. WPF and the Model-View-ViewModel Pattern

5. Synchronizing the Data

Page 22: Building an Offline Smart Client using Domain-Driven Design Principles

The Layered Architecture

Application LayerDomain Layer

Repository StrategyLayered Supertype Pattern

Infrastructure LayerPresentation Layer

Page 23: Building an Offline Smart Client using Domain-Driven Design Principles

Demonstration #1

Layers represented in the SmartCA Visual Studio Solution

Page 24: Building an Offline Smart Client using Domain-Driven Design Principles

Repository Framework

InterfacesRepository FactoryUnit of WorkRepository Base Classes

Page 25: Building an Offline Smart Client using Domain-Driven Design Principles

Demonstration #2

Repository Framework Implementation

Page 26: Building an Offline Smart Client using Domain-Driven Design Principles

Mapping - Entity Factory Framework

InterfacesEntity Factory Builder

Page 27: Building an Offline Smart Client using Domain-Driven Design Principles

Demonstration #3

Entity Factory Framework Implementation

Page 28: Building an Offline Smart Client using Domain-Driven Design Principles

Agenda

1. DDD Definitions/Patterns

2. The SmartCA Application

3. Designing the Layered Architecture

4. WPF and the Model-View-ViewModel Pattern

5. Synchronizing the Data

Page 29: Building an Offline Smart Client using Domain-Driven Design Principles

Windows Presentation Foundation (WPF)

Declarative Programming (Using XAML)Built-in Command PatternStrong Data Binding Support

Page 30: Building an Offline Smart Client using Domain-Driven Design Principles

Model-View-ViewModel Pattern

Traditional Presentation PatternsMVPMVCMore…

Model-View-ViewModel DefinitionWhat’s a ViewModel?

Page 31: Building an Offline Smart Client using Domain-Driven Design Principles

Demonstration #4

Model-View-ViewModel

Page 32: Building an Offline Smart Client using Domain-Driven Design Principles

Agenda

1. DDD Definitions/Patterns

2. The SmartCA Application

3. Designing the Layered Architecture

4. WPF and the Model-View-ViewModel Pattern

5. Synchronizing the Data

Page 33: Building an Offline Smart Client using Domain-Driven Design Principles

Synchronizing the Data – Some Choices

SQL ReplicationADO.NET Synchronization ServicesMessage-Based

Taking advantage of Unit of WorkCan talk to any message-based server

Page 34: Building an Offline Smart Client using Domain-Driven Design Principles

Message-Base Synchronization

Page 35: Building an Offline Smart Client using Domain-Driven Design Principles

Demonstration #5

Data Synchronization

Page 36: Building an Offline Smart Client using Domain-Driven Design Principles

Resources

[Evans]: Domain-Driven Design: Tackling Complexity in the Heart of Software, Evans, Addison-Wesley (2003)

[Fowler]: Patterns of Enterprise Application Architecture, Fowler, Addison-Wesley (2003)

[Nilsson]: Applying Domain Driven Design and Patterns: using .NET, Addison Wesley 2006

Page 37: Building an Offline Smart Client using Domain-Driven Design Principles

Tim McCarthy, InterKnowlogyGet the Demos & PPT at:

Slides: http://www.umlchina.comCode: codeplex.com/dddpds.NET Domain-Driven Design with C#: Problem-Design

-SolutionContact me: Tim McCarthy

E-mail: [email protected] Tim McCarthy

.NET Architect/Dev Lead/TrainerAuthor / SpeakerMCSD, MCSD.NET, MCDBA, MCT, IEEE CSDP