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

Http:// Building an Offline Smart Client using Domain-Driven Design Principles Tim McCarthy

Embed Size (px)

Citation preview

http://www.umlchina.com

Building an Offline Smart Client using Domain-Driven Design Principles

Tim McCarthy

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

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

What is Domain-Driven Design (DDD)?

Sponsor Logo

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!

Ubiquitous Language

Common terms between business experts and development team

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

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

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

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

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!

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

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

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

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!

Pattern: Layered Architecture

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

The SmartCA Application

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

New System RequirementsTechnologiesLayered Architecture

The Legacy Application

New System Requirements

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

functionalityAdditional client device support

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

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

The Layered Architecture

Application LayerDomain Layer

Repository StrategyLayered Supertype Pattern

Infrastructure LayerPresentation Layer

Demonstration #1

Layers represented in the SmartCA Visual Studio Solution

Repository Framework

InterfacesRepository FactoryUnit of WorkRepository Base Classes

Demonstration #2

Repository Framework Implementation

Mapping - Entity Factory Framework

InterfacesEntity Factory Builder

Demonstration #3

Entity Factory Framework Implementation

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

Windows Presentation Foundation (WPF)

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

Model-View-ViewModel Pattern

Traditional Presentation PatternsMVPMVCMore…

Model-View-ViewModel DefinitionWhat’s a ViewModel?

Demonstration #4

Model-View-ViewModel

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

Synchronizing the Data – Some Choices

SQL ReplicationADO.NET Synchronization ServicesMessage-Based

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

Message-Base Synchronization

Demonstration #5

Data Synchronization

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

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