Implementing Domain-Driven Design

Book description

“For software developers of all experience levels looking to improve their results, and design and implement domain-driven enterprise applications consistently with the best current state of professional practice, Implementing Domain-Driven Design will impart a treasure trove of knowledge hard won within the DDD and enterprise application architecture communities over the last couple decades.”

–Randy Stafford, Architect At-Large, Oracle Coherence Product Development

“This book is a must-read for anybody looking to put DDD into practice.”

–Udi Dahan, Founder of NServiceBus

Implementing Domain-Driven Design presents a top-down approach to understanding domain-driven design (DDD) in a way that fluently connects strategic patterns to fundamental tactical programming tools. Vaughn Vernon couples guided approaches to implementation with modern architectures, highlighting the importance and value of focusing on the business domain while balancing technical considerations.

Building on Eric Evans’ seminal book, Domain-Driven Design, the author presents practical DDD techniques through examples from familiar domains. Each principle is backed up by realistic Java examples–all applicable to C# developers–and all content is tied together by a single case study: the delivery of a large-scale Scrum-based SaaS system for a multitenant environment.

The author takes you far beyond “DDD-lite” approaches that embrace DDD solely as a technical toolset, and shows you how to fully leverage DDD’s “strategic design patterns” using Bounded Context, Context Maps, and the Ubiquitous Language. Using these techniques and examples, you can reduce time to market and improve quality, as you build software that is more flexible, more scalable, and more tightly aligned to business goals.

Coverage includes

  • Getting started the right way with DDD, so you can rapidly gain value from it

  • Using DDD within diverse architectures, including Hexagonal, SOA, REST, CQRS, Event-Driven, and Fabric/Grid-Based

  • Appropriately designing and applying Entities–and learning when to use Value Objects instead

  • Mastering DDD’s powerful new Domain Events technique

  • Designing Repositories for ORM, NoSQL, and other databases

  • Table of contents

    1. Title Page
    2. Copyright Page
    3. Praise for Implementing Domain-Driven Design
    4. Dedication Page
    5. Contents
    6. Foreword
    7. Preface
      1. Getting Grounded, Getting Airborne
      2. Landing with Domain-Driven Design
      3. Mapping the Terrain and Charting for Flight
      4. Summary of Chapters
        1. Chapter 1: Getting Started with DDD
        2. Chapter 2: Domains, Subdomains, and Bounded Contexts
        3. Chapter 3: Context Maps
        4. Chapter 4: Architecture
        5. Chapter 5: Entities
        6. Chapter 6: Value Objects
        7. Chapter 7: Services
        8. Chapter 8: Domain Events
        9. Chapter 9: Modules
        10. Chapter 10: Aggregates
        11. Chapter 11: Factories
        12. Chapter 12: Repositories
        13. Chapter 13: Integrating Bounded Contexts
        14. Chapter 14: Application
        15. Appendix A: Aggregates and Event Sourcing: A+ES
      5. Java and Development Tools
    8. Acknowledgments
    9. About the Author
    10. Guide to This Book
      1. Big-Picture View of DDD
        1. Strategic Modeling
        2. Architecture
        3. Tactical Modeling
    11. Chapter 1. Getting Started with DDD
      1. Can I DDD?
      2. Why You Should Do DDD
        1. Delivering Business Value Can Be Elusive
        2. How DDD Helps
        3. Grappling with the Complexity of Your Domain
        4. Anemia and Memory Loss
      3. How to Do DDD
        1. Ubiquitous Language
      4. The Business Value of Using DDD
        1. 1. The Organization Gains a Useful Model of Its Domain
        2. 2. A Refined, Precise Definition and Understanding of the Business Is Developed
        3. 3. Domain Experts Contribute to Software Design
        4. 4. A Better User Experience Is Gained
        5. 5. Clean Boundaries Are Placed around Pure Models
        6. 6. Enterprise Architecture Is Better Organized
        7. 7. Agile, Iterative, Continuous Modeling Is Used
        8. 8. New Tools, Both Strategic and Tactical, Are Employed
      5. The Challenges of Applying DDD
        1. Justification for Domain Modeling
        2. DDD Is Not Heavy
      6. Fiction, with Bucketfuls of Reality
      7. Wrap-Up
    12. Chapter 2. Domains, Subdomains, and Bounded Contexts
      1. Big Picture
        1. Subdomains and Bounded Contexts at Work
        2. Focus on the Core Domain
      2. Why Strategic Design Is So Incredibly Essential
      3. Real-World Domains and Subdomains
      4. Making Sense of Bounded Contexts
        1. Room for More than the Model
        2. Size of Bounded Contexts
        3. Aligning with Technical Components
      5. Sample Contexts
        1. Collaboration Context
        2. Identity and Access Context
        3. Agile Project Management Context
      6. Wrap-Up
    13. Chapter 3. Context Maps
      1. Why Context Maps Are So Essential
        1. Drawing Context Maps
        2. Projects and Organizational Relationships
        3. Mapping the Three Contexts
      2. Wrap-Up
    14. Chapter 4. Architecture
      1. Interviewing the Successful CIO
      2. Layers
        1. Dependency Inversion Principle
      3. Hexagonal or Ports and Adapters
      4. Service-Oriented
      5. Representational State Transfer–REST
        1. Contributed by Stefan Tilkov
        2. REST as an Architectural Style
        3. Key Aspects of a RESTful HTTP Server
        4. Key Aspects of a RESTful HTTP Client
        5. REST and DDD
        6. Why REST?
      6. Command-Query Responsibility Segregation, or CQRS
        1. Examining Areas of CQRS
        2. Dealing with an Eventually Consistent Query Model
      7. Event-Driven Architecture
        1. Pipes and Filters
        2. Long-Running Processes, aka Sagas
        3. Event Sourcing
      8. Data Fabric and Grid-Based Distributed Computing
        1. Contributed by Wes Williams
        2. Data Replication
        3. Event-Driven Fabrics and Domain Events
        4. Continuous Queries
        5. Distributed Processing
      9. Wrap-Up
    15. Chapter 5. Entities
      1. Why We Use Entities
      2. Unique Identity
        1. User Provides Identity
        2. Application Generates Identity
        3. Persistence Mechanism Generates Identity
        4. Another Bounded Context Assigns Identity
        5. When the Timing of Identity Generation Matters
        6. Surrogate Identity
        7. Identity Stability
      3. Discovering Entities and Their Intrinsic Characteristics
        1. Uncovering Entities and Properties
        2. Digging for Essential Behavior
        3. Roles and Responsibilities
        4. Construction
        5. Validation
        6. Change Tracking
      4. Wrap-Up
    16. Chapter 6. Value Objects
      1. Value Characteristics
        1. Measures, Quantifies, or Describes
        2. Immutable
        3. Conceptual Whole
        4. Replaceability
        5. Value Equality
        6. Side-Effect-Free Behavior
      2. Integrate with Minimalism
      3. Standard Types Expressed as Values
      4. Testing Value Objects
      5. Implementation
      6. Persisting Value Objects
        1. Reject Undue Influence of Data Model Leakage
        2. ORM and Single Value Objects
        3. ORM and Many Values Serialized into a Single Column
        4. ORM and Many Values Backed by a Database Entity
        5. ORM and Many Values Backed by a Join Table
        6. ORM and Enum-as-State Objects
      7. Wrap-Up
    17. Chapter 7. Services
      1. What a Domain Service Is (but First, What It Is Not)
      2. Make Sure You Need a Service
      3. Modeling a Service in the Domain
        1. Is Separated Interface a Necessity?
        2. A Calculation Process
        3. Transformation Services
        4. Using a Mini-Layer of Domain Services
      4. Testing Services
      5. Wrap-Up
    18. Chapter 8. Domain Events
      1. The When and Why of Domain Events
      2. Modeling Events
        1. With Aggregate Characteristics
        2. Identity
      3. Publishing Events from the Domain Model
        1. Publisher
        2. Subscribers
      4. Spreading the News to Remote Bounded Contexts
        1. Messaging Infrastructure Consistency
        2. Autonomous Services and Systems
        3. Latency Tolerances
      5. Event Store
      6. Architectural Styles for Forwarding Stored Events
        1. Publishing Notifications as RESTful Resources
        2. Publishing Notifications through Messaging Middleware
      7. Implementation
        1. Publishing the NotificationLog
        2. Publishing Message-Based Notifications
      8. Wrap-Up
    19. Chapter 9. Modules
      1. Designing with Modules
      2. Basic Module Naming Conventions
      3. Module Naming Conventions for the Model
      4. Modules of the Agile Project Management Context
      5. Modules in Other Layers
      6. Module before Bounded Context
      7. Wrap-Up
    20. Chapter 10. Aggregates
      1. Using Aggregates in the Scrum Core Domain
        1. First Attempt: Large-Cluster Aggregate
        2. Second Attempt: Multiple Aggregates
      2. Rule: Model True Invariants in Consistency Boundaries
      3. Rule: Design Small Aggregates
        1. Don’t Trust Every Use Case
      4. Rule: Reference Other Aggregates by Identity
        1. Making Aggregates Work Together through Identity References
        2. Model Navigation
        3. Scalability and Distribution
      5. Rule: Use Eventual Consistency Outside the Boundary
        1. Ask Whose Job It Is
      6. Reasons to Break the Rules
        1. Reason One: User Interface Convenience
        2. Reason Two: Lack of Technical Mechanisms
        3. Reason Three: Global Transactions
        4. Reason Four: Query Performance
        5. Adhering to the Rules
      7. Gaining Insight through Discovery
        1. Rethinking the Design, Again
        2. Estimating Aggregate Cost
        3. Common Usage Scenarios
        4. Memory Consumption
        5. Exploring Another Alternative Design
        6. Implementing Eventual Consistency
        7. Is It the Team Member’s Job?
        8. Time for Decisions
      8. Implementation
        1. Create a Root Entity with Unique Identity
        2. Favor Value Object Parts
        3. Using Law of Demeter and Tell, Don’t Ask
        4. Optimistic Concurrency
        5. Avoid Dependency Injection
      9. Wrap-Up
    21. Chapter 11. Factories
      1. Factories in the Domain Model
      2. Factory Method on Aggregate Root
        1. Creating CalendarEntry Instances
        2. Creating Discussion Instances
      3. Factory on Service
      4. Wrap-Up
    22. Chapter 12. Repositories
      1. Collection-Oriented Repositories
        1. Hibernate Implementation
        2. Considerations for a TopLink Implementation
      2. Persistence-Oriented Repositories
        1. Coherence Implementation
        2. MongoDB Implementation
      3. Additional Behavior
      4. Managing Transactions
        1. A Warning
      5. Type Hierarchies
      6. Repository versus Data Access Object
      7. Testing Repositories
        1. Testing with In-Memory Implementations
      8. Wrap-Up
    23. Chapter 13. Integrating Bounded Contexts
      1. Integration Basics
        1. Distributed Systems Are Fundamentally Different
        2. Exchanging Information across System Boundaries
      2. Integration Using RESTful Resources
        1. Implementing the RESTful Resource
        2. Implementing the REST Client Using an Anticorruption Layer
      3. Integration Using Messaging
        1. Staying Informed about Product Owners and Team Members
        2. Can You Handle the Responsibility?
        3. Long-Running Processes, and Avoiding Responsibility
        4. Process State Machines and Time-out Trackers
        5. Designing a More Sophisticated Process
        6. When Messaging or Your System Is Unavailable
      4. Wrap-Up
    24. Chapter 14. Application
      1. User Interface
        1. Rendering Domain Objects
        2. Render Data Transfer Object from Aggregate Instances
        3. Use a Mediator to Publish Aggregate Internal State
        4. Render Aggregate Instances from a Domain Payload Object
        5. State Representations of Aggregate Instances
        6. Use Case Optimal Repository Queries
        7. Dealing with Multiple, Disparate Clients
        8. Rendition Adapters and Handling User Edits
      2. Application Services
        1. Sample Application Service
        2. Decoupled Service Output
      3. Composing Multiple Bounded Contexts
      4. Infrastructure
      5. Enterprise Component Containers
      6. Wrap-Up
    25. Appendix A. Aggregates and Event Sourcing: A+ES
      1. Inside an Application Service
      2. Command Handlers
      3. Lambda Syntax
      4. Concurrency Control
      5. Structural Freedom with A+ES
      6. Performance
      7. Implementing an Event Store
      8. Relational Persistence
      9. BLOB Persistence
      10. Focused Aggregates
      11. Read Model Projections
      12. Use with Aggregate Design
      13. Events Enrichment
      14. Supporting Tools and Patterns
        1. Event Serializers
        2. Event Immutability
        3. Value Objects
      15. Contract Generation
      16. Unit Testing and Specifications
      17. Event Sourcing in Functional Languages
    26. Bibliography
    27. Index

    Product information

    • Title: Implementing Domain-Driven Design
    • Author(s):
    • Release date: February 2013
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780133039900