One way or another, each system contains some kind of boundaries. I would go so far and claim that even the dreaded Big Ball of Mud systems consist of parts that could be perceived as separate though undoubtedly only under deep scrutiny. The difference is in the “thickness” of the boundaries and the measure of interrelationships between the different parts of the system, the frequency and amount of data that is passed across the fences. It is the latter that leads to increased coupling resulting in systems that are hard to maintain and hard to change.
This presentation will present a story of an attempt to achieve an alignment between perceived subdomains, logical boundaries and source code structure in a legacy system. Based on the use case from healthcare we will go into technical detail on concrete steps that were followed to create a new bounded context using strategic Domain-Driven Design and 4+1 Architectural View Models.
5. Strategic DDD
• Focusing on Core domain
• Problem and solution space
• Subdomains and Bounded Contexts
• Linguistic boundaries
• Ubiquitous Language
• The two pillars of DDD
6. Core Domain
• The thing that distinguishes you
from the competitors
• “Not every part of the system will be
well-designed”
• Generic subdomain
• Supporting subdomain
7. Problem Space
and
Solution Space
Problem space
• Domain analysis to discover
inherent Subdomains
Solution space
• Model your application accordingly
in multiple Bounded Contexts
21. Cost of
Dependencies in a
Distributed System
• Distributed logical dependencies
• Across software and process views
• Across the organization
• Microservices
23. Business Case
• Physicians prescribe medications
• Integration with systems for
prescription delivery in pharmacies
• Focus on putting patient needs and
safety on the top
40. Subdomains in
Problem Space
• Pivotal Event
• NonApprovedMedicationPrescribed
• Time-related activity
• While waiting for approval the
physician stops the prescription
process
42. Traces of Bounded
Contexts in
Development View
• Are there any established
boundaries in the Development
View?
• 4+1 Model
• .NET projects
• Namespaces
43. Dependencies in
Logical View
• Analysis of
• using statements
• .NET project references
• NuGet package references
• Http calls to remote services
• Event-based communication with
remote services
45. DDD Context Mapping
Downstream: depending on upstream
Upstream: depended on downstream
Conformist: Upstream model referenced directly in Downstream context
46. Bounded Contexts
in Legacy Code
• Respect existing dependencies and
relationships
• Explicit decision on the amount of
work needed to break things up
50. Move existing .NET projects
• Between solutions within the same repository
• git mv
• Exclude/Include Project
Code compiles and unit tests run
51. Integration tests?
• Valuable enough feedback with unit
tests only?
• Integration/E2E tests
• Harder to maintain
• Can provide runtime feedback
52. Work on E2E tests?
• Pros
• Early feedback on bounded context/subdomain alignment
• Cons
• Considerable work needed just to get the tests running
• Could actually slow down the feedback loop
Focus on unit tests only at this stage
59. The end of the story….
• Some E2E tests in Prescription context required DLLs from
Application context
• Why?
60. Valid business reason for Prescription BC to refer to Application BC
- Beware of Circular Dependencies!
61. Business requirement unlocked
• As a physician while prescribing a non-approved medicament
• I need to see prior applications for the same medicament
• To be able to prescribe non-approved medicaments on a life-long
basis if required by patient condition
Requires dependency from Prescription BC to Application BC
62. Can we avoid
circular
dependencies?
• 4+1 model
• Deployment dependencies ok
• Circular logical dependencies
• All the integration tests in one
module
• Referencing different bounded
contexts
• All DLLs would be available
63.
64. View Model
Composition • Composing data from different
Bounded Contexts on front-end
• Suggested reading
• Mauro Servienti
• https://milestone.topics.it/
• The physician needs only to see the
prior applications
• Data shown for decision-support
65. Takeaways for the Team
▪ Regular Architectural Reviews
– continuous learning about subdomain boundaries
▪ Stable Abstraction Principle
– Define desired relationships between the modules
▪ Discover Logical Dependencies in Code Review
– 4+1 Model
▪ “You can always make things more cohesive”
– Kent Beck
Ella Fitzegerald –
«They Cant’t Take That Away From Me»