I’m a big fan of the Domain-Driven Design (DDD) principles and patterns so pre-ordered Vaughn Vernon’s “Implementing Domain-Driven Design” prior to it’s release in March this year (2013). Having finished it earlier this week I wanted to do some justice to this invaluable text by posting a blog which provides a synopsis of each chapter, as well as some general commentary about the book.
If you don’t read any further let me say, before you go, that if you’re interested in learning about DDD, or want a modern and comprehensive DDD reference book, then get your hands on a copy. This text easily gets a 5 star rating from me, which is akin to the ratings on Amazon.com and Amazon.co.uk at the time of writing.
A Few Brief Notes
“Implementing Domain-Driven Design“ is a very comprehensive book on DDD, to say the least, and will serve it’s owners well as a reference text just as much as it will as an informative guide to DDD. There is a sample solution that runs throughout the book so each chapter makes some pertinent reference to how the topic at hand can be applied to the solution. If you’re a C# developer don’t be too alarmed that Java is the language of choice throughout the book, I haven’t touched Java in years and I managed to keep up (for the most part :)). One thing I will say is if your not familiar with a lot of the more common design and architectural patterns in use today either be prepared to learn them as you go, or do some preliminary swatting up – they’re littered throughout the book as you can expect.
All up the book covers a lot of ground and personally I think the author did an excellent job. Even when summarising the chapters I found that I was leaving quite a bit out as they’re all so incredibly comprehensive. If there was anything I would change it’d be making a reference to my favourite IDE and tools throughout, but I acknowledge that doing so would more than likely drive the Java readers mad so I don’t fault the author for his choice.
In a lot of ways DDD can be seen as a tool for architects and developers and I personally felt better equipped to use my DDD tools and skillset out in the real world after having read “Implementing Domain-Driven Design” by Vaughn Vernon.
1. Getting Started with DDD
This chapter introduces a broad number of DDD terms, but nothing as involved as what follows in subsequent chapters. Also included is a brief review of how to evaluate projects, some sample hand-ons pointers as to how improvements can be addressed via DDD practices, and an introduction to a sample team and their projects which will be referenced throughout the book. All up it’s a great chapter and I was impressed at how engaging Vaughn Vernon managed to make it. You come away with a broad idea of how involved and encompassing DDD is with a number of practical illustrations along the way.
2. Domains, Subdomains, and Bounded Contexts
As the title suggests Domains, Subdomains and Bounded Contexts get a very thorough work over – all of the main elements of a DDD strategic design. Core Domains, Supporting and Generic Subdomains, are also addressed as well as why it’s important to adopt a strategic design approach when analysing the problem and solution spaces. Each section contains a number of short hands-on workshops, and direct questions you can answer to better understand each concept and it’s relevance to a solution you are, or may be about to, work on. A number of common strategic design pitfalls to avoid are raised as well as a strong emphasis on key factors not to misinterpret or misunderstand.
3. Context Maps
This chapter focuses on the solution space (as opposed to the problem space discussed in the previous chapter) which brings to light the concept of Context Maps; how two Bounded Contexts are related. This benefits the solution design as well as helping map out Bounded Context communication and inter-team communication on larger solutions where each team is responsible for a given Context. As well as covering all of the essential terminologies and business practices that are associated with Context Maps the author provides a detailed overview of how Context Maps are applied from high-level diagrams down to the source code.
This is quite the comprehensive chapter, and a very well presented one. As the name suggests it’s about architecture and covers a lot of architectural patterns relevant to enterprise solutions as well as making reference to what approaches to take with medium-scaled solutions where the complexity and demand is less involved. The list of topics covered is quite comprehensive so I’ll provide an abbreviated list; Layer Architecture (before and after DI is introduced), Ports and Adapters Architecture (Hexagonal/Onion), use-case driven and event-driven architecutre, CQRS, sagas, SOA, REST, grid-based distributed computing etc.
The fundamentals as to what constitutes an Entity and how it’s utilised in a DDD solution are covered. Related topics such as Entity identity generation (and considerations), validation, how each particular Service or tiers interact with Entities, and some practical implementations of Entities as well as influences by some modern day frameworks and data stores are also discussed.
6. Value Objects
Value Objects, programmatic and design concepts that “describe a thing in the domain” (p.221) are covered in detail. It gets a good deal of coverage as it’s correct application over Entities is of great benefit in a DDD solution. Side-effect free behaviour, Whole Value replacement, immutability, initialisation, value equality, no requirement for a unique constraint, easier to test and maintain, no restriction on size or complexity, etc. are all addressed.
Covering both Application services and Domain services, providing solid definitions and ample architectural and code examples. As noted by the author it’s important to understand what a “service” is, and what it is not, when constructing a DDD solution so that you avoid incorrect practices that can lead to anaemic domain models and other anti-patterns. Some attention is paid to service testing as well.
8. Domain Events
Domain Events are considered part of the larger domain model as they are something that occurs within the Domain. Because Domain Events can be implemented in a number of ways, each requiring a high level of system design understanding, the chapter does delve into more complexity than some of the previous chapters. You’ll certainly come away with a better understanding of Domain Events and the scalability it provides but will definitely need to do some extra reading to know how best to apply them in a given solution – this isn’t a critique, there are simply a lot of ways to implement this particular DDD element.
This is one of the shorter chapters, given it’s not really the first thing that springs to mind when you think about DDD. However constructing modules is still a key element to solution design so it’s good to know it’s given ample attention. Cohesive, low-coupled, modules are discussed, general guidelines to follow, the importance of introducing the Ubiquitous Language into the naming of modules, all with reference to both Java and C#.
My understanding of Aggregates, prior to reading this chapter, was based on a number of other sources who never explained it as well, or in as much detail as Vernon Vaughn so I came away from this chapter with a more comprehensive understanding of Aggregates than I’d had before, and learnt a few new modelling techniques along the way. Aggregate modelling, Aggregate relationships, root Aggregates, size considerations, true/false invariants, transactional handling, transactional/eventual consistency, etc. are all covered. Great chapter.
Using factories in the domain model is the focus (… as you’ve probably guessed) regardless of the specific design pattern; Abstract Factory, Factory Method or Builder. A very short chapter that covers the essentials.
The illusionary in-memory data store of objects 🙂 is given ample attention in this chapter. Both the common approach of one-to-one repository-to-aggregate approach is covered as well as the not so common approach when a single repository covers more than one Aggregate type. An abundance of Hibernate examples are provided, as well as a few TopLink (UoW), with regards to repository collection-oriented design. In contrast the other type of Repository design; persistence-oriented design, is also given quite a bit of attention with a NoSQL approach (namely MongoDB). A number of very helpful tips are provided to address the less standard Repository design scenarios as well as a robust testing approach. I could go on but suffice to say this is a very comprehensive chapter.
13. Integrating Bounded Contexts
A very detailed coverage of integrating distributed environments, with particular emphasis on RESTful HTTP and messaging mechanisms. A lot of attention is paid to the latter and there are no shortage of code samples. All up it’s a very detailed chapter with ample theory, considerations and recommendations to put into practice.
A very, very informative and well presented chapter. The main focus is on the Application Layer with attention paid to it’s responsibilities, the layers on either side (UI, Domain), and how they all work together … in a loosely coupled fashion that is :).
Appendix A. Aggregates and Event Sourcing: A+ES
The Appendix is contributed by a separate author that builds on top of Vernon’s text, covering the topic of Aggregates and Event Sourcing.
Vaughn Verson has a website at vaughnvernon.co/ and a GitHub repository github.com/VaughnVernon/ if you’re interested. The latter has the sample code from the book which is something that I didn’t find referenced in the text.
If you purchase the hard copy of the book then Safari Books Online provide 45 days access to an online copy – note that’s “online copy”, not an electronic copy that you can save locally. Darn.
As noted earlier this is a great book, and I would recommend picking it up if you enjoy using DDD, or are an experienced software engineer looking to learn more about DDD.