Introdution
- High-level modules should not depend on low-level modules. Both should depend on abstractions.
- Abstractions should not depend on details. Instead, details should depend on abstractions.
Domain Modeling
book/chapter_01_domain_model.asciidoc at master · cosmicpython/book
和领域专家沟通了解领域模型
领域模型的三个概念:
- Value Objects
- Entities
- domain service
领域建模
- Domain modeling
- Distinguish entities from value objects
- Not everything has to be an object
- This is the time to apply your best OO design principles
- You’ll also want to think about consistency boundaries and aggregates
python
- dataclasses、NewType
- eq , hash
- next
- attrs · PyPI
软件工程
- TDD
- UML
疑问
- 图里的虚线、实线是什么意思?
Repository Pattern
The Repository pattern is an abstraction over persistent storage
+-----------------------------+
| Application Layer |
+-----------------------------+
|^
|| /------------------\
||----------| Domain Model |
|| | Objects |
|| \------------------/
V|
+------------------------------+
| Repository |
+------------------------------+
|
V
+------------------------------+
| Database Layer |
+------------------------------+
- book/chapter_02_repository.asciidoc at master · cosmicpython/book
- cosmicpython/code at chapter_02_repository
主要内容:如何使用依赖反转将领域模型和数据库解耦
- 传统Layered architecture和Onion architecture的差别
- 如何实现Inverting the Dependency: ORM Depends on Model (以SQLAlchemy为例)
- 如何测试domain -> repo
- 如何测试repo -> database
- 如何创建一个Fake repo进行测试
- 使用Repository Pattern的tradeoff(Pros and cons)
拓展阅读
除另有声明外,本博客文章均采用 知识共享(Creative Commons) 署名-非商业性使用-相同方式共享 3.0 中国大陆许可协议 进行许可。