1 / 37

Building an Offline Smart Client using Domain-Driven Design Principles

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

gomer
Download Presentation

Building an Offline Smart Client using Domain-Driven Design Principles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building an Offline Smart Client using Domain-Driven Design Principles Tim McCarthy

  2. Agenda • DDD Definitions/Patterns • The SmartCA Application • Designing the Layered Architecture • WPF and the Model-View-ViewModel Pattern • Synchronizing the Data

  3. Agenda • DDD Definitions/Patterns • The SmartCA Application • Designing the Layered Architecture • WPF and the Model-View-ViewModel Pattern • Synchronizing the Data

  4. What is Domain-Driven Design (DDD)? Sponsor Logo

  5. 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!

  6. Ubiquitous Language • Common terms between business experts and development team • Use the language in your code • Namespaces • Class, property, method, variable names

  7. 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

  8. 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

  9. 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

  10. 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!

  11. 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

  12. 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

  13. 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

  14. 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!

  15. Pattern: Layered Architecture

  16. Agenda • DDD Definitions/Patterns • The SmartCA Application • Designing the Layered Architecture • WPF and the Model-View-ViewModel Pattern • Synchronizing the Data

  17. The SmartCA Application • Problem – Legacy MS Access Application • a.k.a. Smart Client Anti-Pattern • New System Requirements • Technologies • Layered Architecture

  18. The Legacy Application

  19. New System Requirements Reliability and Availability Scalability Maintainability Rich client application functionality Offline Capable Intelligent installation and auto-update functionality Additional client device support

  20. 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

  21. Agenda • DDD Definitions/Patterns • The SmartCA Application • Designing the Layered Architecture • WPF and the Model-View-ViewModel Pattern • Synchronizing the Data

  22. The Layered Architecture • Application Layer • Domain Layer • Repository Strategy • Layered Supertype Pattern • Infrastructure Layer • Presentation Layer

  23. Demonstration #1 Layers represented in the SmartCA Visual Studio Solution

  24. Repository Framework Interfaces Repository Factory Unit of Work Repository Base Classes

  25. Demonstration #2 Repository Framework Implementation

  26. Mapping - Entity Factory Framework Interfaces Entity Factory Builder

  27. Demonstration #3 Entity Factory Framework Implementation

  28. Agenda • DDD Definitions/Patterns • The SmartCA Application • Designing the Layered Architecture • WPF and the Model-View-ViewModel Pattern • Synchronizing the Data

  29. Windows Presentation Foundation (WPF) Declarative Programming (Using XAML) Built-in Command Pattern Strong Data Binding Support

  30. Model-View-ViewModel Pattern • Traditional Presentation Patterns • MVP • MVC • More… • Model-View-ViewModel Definition • What’s a ViewModel?

  31. Demonstration #4 Model-View-ViewModel

  32. Agenda • DDD Definitions/Patterns • The SmartCA Application • Designing the Layered Architecture • WPF and the Model-View-ViewModel Pattern • Synchronizing the Data

  33. 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

  34. Message-Base Synchronization

  35. Demonstration #5 Data Synchronization

  36. 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

  37. Tim McCarthy, InterKnowlogy • Get the Demos & PPT at: • Slides: http://www.umlchina.com • Code: codeplex.com/dddpds • .NET Domain-Driven Design with C#: Problem-Design-Solution • Contact me: Tim McCarthy • E-mail: tmccart1@san.rr.com • About Tim McCarthy • .NET Architect/Dev Lead/Trainer • Author / Speaker • MCSD, MCSD.NET, MCDBA, MCT, • IEEE CSDP

More Related