Presentation Title - UMLChina-

Download Report

Transcript Presentation Title - UMLChina-

http://www.umlchina.com
Building an Offline Smart Client
using Domain-Driven Design
Principles
Tim McCarthy
Agenda
1.
2.
3.
4.
DDD Definitions/Patterns
The SmartCA Application
Designing the Layered Architecture
WPF and the Model-View-ViewModel
Pattern
5. Synchronizing the Data
Agenda
1.
2.
3.
4.
DDD Definitions/Patterns
The SmartCA Application
Designing the Layered Architecture
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 code
Namespaces
Class, property, method, variable names
Communicating the Language
Create whiteboard drawings
Favor whiteboarding over Visio
Use digital camera to capture, then paste into
Word
Use Visual Studio class diagrams for core
parts of the domain
Code and diagram are kept in sync
No wasted time diagramming, your diagram is
the code
Definition: Entities
An object defined primarily by its identity
Not 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 boundary
Boundary = what is inside the AGGREGATE
Root = single ENTITY inside the
AGGREGATE
Hardest but most important concept to
understand in DDD!
Aggregate Rules
The root ENTITY has global identity
ENTITIES inside the boundary have local
identity
Nothing 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
Stateless
To 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 ENTITIES
Example: a common Id property
Helps eliminate duplicate code
Pattern: Repository
Provide access to AGGREGATE roots
Represents 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.
2.
3.
4.
DDD Definitions/Patterns
The SmartCA Application
Designing the Layered Architecture
WPF and the Model-View-ViewModel
Pattern
5. Synchronizing the Data
The SmartCA Application
Problem – Legacy MS Access Application
a.k.a. Smart Client Anti-Pattern
New System Requirements
Technologies
Layered Architecture
The Legacy Application
New System Requirements
Reliability and Availability
Scalability
Maintainability
Rich client application functionality
Offline Capable
Intelligent installation and auto-update
functionality
Additional client device support
The New Solution – SmartCA Application
DDD with Layered Architecture
UI = WPF Smart Client
Data Store
Server – behind web services cloud
Client – SQL Server Compact Edition 3.5
Agenda
1.
2.
3.
4.
DDD Definitions/Patterns
The SmartCA Application
Designing the Layered Architecture
WPF and the Model-View-ViewModel
Pattern
5. Synchronizing the Data
The Layered Architecture
Application Layer
Domain Layer
Repository Strategy
Layered Supertype Pattern
Infrastructure Layer
Presentation Layer
Demonstration #1
Layers represented in the SmartCA Visual
Studio Solution
Repository Framework
Interfaces
Repository Factory
Unit of Work
Repository Base Classes
Demonstration #2
Repository Framework Implementation
Mapping - Entity Factory Framework
Interfaces
Entity Factory Builder
Demonstration #3
Entity Factory Framework Implementation
Agenda
1.
2.
3.
4.
DDD Definitions/Patterns
The SmartCA Application
Designing the Layered Architecture
WPF and the Model-View-ViewModel
Pattern
5. Synchronizing the Data
Windows Presentation Foundation (WPF)
Declarative Programming (Using XAML)
Built-in Command Pattern
Strong Data Binding Support
Model-View-ViewModel Pattern
Traditional Presentation Patterns
MVP
MVC
More…
Model-View-ViewModel Definition
What’s a ViewModel?
Demonstration #4
Model-View-ViewModel
Agenda
1.
2.
3.
4.
DDD Definitions/Patterns
The SmartCA Application
Designing the Layered Architecture
WPF and the Model-View-ViewModel
Pattern
5. Synchronizing the Data
Synchronizing the Data – Some Choices
SQL Replication
ADO.NET Synchronization Services
Message-Based
Taking advantage of Unit of Work
Can 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, AddisonWesley (2003)
[Nilsson]: Applying Domain Driven Design
and Patterns: using .NET, Addison Wesley
2006
Tim McCarthy, InterKnowlogy
Get the Demos & PPT at:
Slides: http://www.umlchina.com
Code: codeplex.com/dddpds
.NET Domain-Driven Design with C#: ProblemDesign-Solution
Contact me: Tim McCarthy
E-mail: [email protected]
About Tim McCarthy
.NET Architect/Dev Lead/Trainer
Author / Speaker
MCSD, MCSD.NET, MCDBA, MCT,
IEEE CSDP