Files
android-client/core/domain/DESIGN_NOTES.md
2026-09-03 19:03:35 +08:00

23 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# DESIGN_NOTES — core:domain
## 为什么纯 Kotlin
`core:domain`(以及 `core:model`、`core:common`)用 `mcl.kotlin.library`(`org.jetbrains.kotlin.jvm`),**不依赖 Android**。这样:
- 业务规则(UseCase)不 import `android.*`,框架解耦,天然可移植。
- 单元测试直接跑在 JVM 上(`./gradlew test`),快且稳定,无需 Robolectric/设备。
## 如何塑造 UseCase / Repository
- **UseCase**:单一动作的接口,`suspend operator fun invoke(input): Output`(见 `UseCase.kt`)。一个类一个动作,符合单一职责。
- **Repository 接口**:定义在 `core:domain`(接口),实现在 `core:data`(`XxxRepositoryImpl`)。调用方只依赖接口,不依赖实现,便于用 fake 替换做测试。
## 依赖方向
`core:domain` 只依赖 `core:model` 与 `core:common`(都是纯 Kotlin)。**不要**让 domain 依赖 Android、网络、数据库——那是数据层的职责。
## 约定
- 需要协程时用 `kotlinx-coroutines-core`(`Flow` 等);不要在 domain 里用 Android 的 `LiveData`。
- 状态/结果优先用 sealed class 表达。