Architecture Patterns with Python
Introduction
Weāve found that many developers, when asked to design a new system, will immediately start to build a database schema, with the object model treated as an afterthought. This is where it all starts to go wrong. Instead,Ā behavior should come first and drive our storage requirements.Ā After all, our customers donāt care about the data model. They care about what the systemĀ does; otherwise theyād just use a spreadsheet.
The first part of the book looks at how to build a rich object model through TDD (inĀ [chapter_01_domain_model|chapter_01_domain_model]), and then weāll show how to keep that model decoupled from technical concerns. We show how to build persistence-ignorant code and how to create stable APIs around our domain so that we can refactor aggressively.
To do that, we present four key design patterns:
- TheĀ Repository pattern, an abstraction over the idea of persistent storage
- TheĀ Service LayerĀ pattern to clearly define where our use cases begin and end
- TheĀ Unit of Work patternĀ to provide atomic operations
- TheĀ Aggregate patternĀ to enforce the integrity of our data
Three layered architecture
Chapter 1.Ā Domain Modeling
- The problem we are trying to solve as a software engineer is called as Domain.
- For an online retailer of furniture, the domain might be purchasing and procurement, or product design, or logistics and delivery.
- Most programmers spend their days trying to improve or automate business processes; the domain is the set of activities that those processes support.
- AĀ modelĀ is a map of a processĀ or phenomenon that captures a useful property.
- The domain model is the mental map that business owners have of their businesses. All business people have these mental mapsātheyāre how humans think about complex processes.