| 계층 | 설명 |
|---|---|
| Domain Layer | 앱의 핵심 비즈니스 로직이 위치. Entity, UseCase, Protocol, Repositpry인터페이스 등이 존재하며, 어떤 프레임워크나 외부에도 의존하지 않음 |
| Data Layer | API, DB 등 실제 데이터 소스와 통신하는 계층. Repository의 구체 구현체가 위치 |
| Presentation Layer | 화면(View)과 사용자와의 상호작용을 처리. ViewModel, UI, 입력 처리 등이 포함됨 |
class ViewModel {
let useCase = UseCase() // ViewModel은 UseCase에 의존
}
| 용어 | 설명 | 예시 |
|---|---|---|
| 고수준 모듈 | 핵심 비즈니스 로직 | UseCase |
| 저수준 모듈 | 세부 구현 (DB, API 등) | Repository |
| 추상화 | 중간 다리 역할 | RepositoryProtocol |
class UseCase {
let repository = Repository() // 구체적인 구현에 직접 의존
}
protocol RepositoryProtocol {
func fetchUsers() -> [User]
}
class UseCase {
private let repository: RepositoryProtocol
init(repository: RepositoryProtocol) {
self.repository = repository
}
}
RepositoryProtocol이라는 추상화된 인터페이스에만 의존한다.let repository = MockUserRepository()
let useCase = FetchUsersUseCase(repository: repository) // 의존성 주입
let viewModel = ViewModel(useCase: useCase)
| 장점 | 설명 |
|---|---|
| 유연성 | 다양한 구현체를 자유롭게 교체 가능 |
| 테스트 용이성 | 테스트 시 Mock 객체를 쉽게 주입 |
| 결합도 감소 | 클래스 간 강한 연결을 피함 |