Repository 模式在一个 collection-like 接口后面抽象了数据访问 — 将业务逻辑与数据如何存储和检索分离开来。它将应用程序与数据源(数据库、API)解耦,改进了可测试性和可维护性。
Repository 模式做什么
REPOSITORY → an abstraction layer between business logic and DATA ACCESS:
→ provides a clean interface (like a collection: findById, save, delete, findAll)
→ HIDES how/where data is actually stored (database, API, cache, files)
→ business logic uses the repository, NOT the database directly
→ separate WHAT data operations from HOW they're implemented
示例
{
() { }
() { }
() { }
}
user = userRepository.();
