lgvv98

Clean Architecture Swift #2 본문

apple/DesignPattern & Architecture

Clean Architecture Swift #2

lgvv 2022. 9. 29. 18:48

Clean Architecture Swift #2

 

여기부터는 클린 아키텍쳐 코드 분석한 내용을 바탕으로 예제를 만들어보려고 합니다.

 

클린 아키텍쳐 연습을 위해 ReactorKit + Moya를 사용

 

CleanArchitecture.zip
0.40MB

🌿 term 🌿

DTO(Data Transfer Object)
계층 간 데이터 교환을 위해 사용하는 객체로, DTO는 로직을 가지지 않는 데이터 객체를 가진 클래스

 

(분석할 프로젝트)

https://github.com/kudoleh/iOS-Clean-Architecture-MVVM

 

GitHub - kudoleh/iOS-Clean-Architecture-MVVM: Template iOS app using Clean Architecture and MVVM. Includes DIContainer, FlowCoor

Template iOS app using Clean Architecture and MVVM. Includes DIContainer, FlowCoordinator, DTO, Response Caching and one of the views in SwiftUI - GitHub - kudoleh/iOS-Clean-Architecture-MVVM: Tem...

github.com

 

 

https://tech.olx.com/clean-architecture-and-mvvm-on-ios-c9d167d9f5b3

 

Clean Architecture and MVVM on iOS

When we develop software it is important to not only use design patterns, but also architectural patterns. There are many different…

tech.olx.com

 

 

When we develop software it is important to not only use design patterns, but also architectural patterns. There are many different architectural patterns in Software Engineering. In mobile software engineering, the most widely used are MVVM, Clean Architecture and Redux patterns.


우리가 소프트웨어 개발할 때 design patterns 뿐만 아니라 architectural patterns 또한 중요합니다.
소프트웨어 엔지니어링에는 다양한 architectural patterns이 있습니다.
모바일 소프트웨어 공학에서 가장 널리 사용되는 것은 MVVM, 클린 아키텍쳐 그리고 Redux 패턴입니다.

 

 

클린 아키텍쳐 + MVVM

 

outers layer에서 inner layers로 depedency rule을 지키는 것이 가장 중요합니다.

 

모든 것은 세개의 레이어로 이루어져 있다.

 

 

Domain Layer는 비즈니스 로직을 담당합니다. 

Entities, Use Cases, Repository가 포함되며, 이 계층은 다른 프로젝트 내에서 재사용될 수 있습니다.

Domain 계층에는 다른 계층이 포함되서는 안됩니다. 예를 들면은 UIKit이나 SwiftUI 혹은 데이터의 Mapping Codable 등이 있습니다.

 

Presentation Layer는 View와 관련한 것들을 담당합니다. View는 하나 이상의 Use Cases를 실행하는 ViewModel에 의해서 조정(Coordinated)됩니다. 

Presentation 계층은 Domain 계층에만 의존합니다.

 

Data Layerdpsms Repository 구현과 하나 이상의 Data Source가 포함됩니다.

Repositiries는 서로 다른 Data Source의 데이터를 조정하는 역할을 합니다.

Data 계층은 오직 Domain 계층에만 의존하며, Data 계층에서 Network 통신을 통한 JSON Mapping(a.k.a codable사용)을 할 수도 있습니다.

 

 

예제 프로젝트의 데이터 흐름

 

위의 그래프를 보면 각 계층의 모든 컴포넌트가 Domain Use Case를 향해서 흐르는데, Data Repository 부분에서 반전되는 것을 확인할 수 있다. 이는 interfaces(protocols)를 사용하여 반전!

 

 

 

✅ 클린 아키텍쳐 연습 

Clean Architecture

 

 

 

 

✅ 결과 UI 

결과 UI

 

 

 

 

클린 아키텍쳐 작성순서 팁!

 

1. 엔티티

2. DTO

3. ServiceAPI 

4. Repository 

5. useCase

6. 레포지토리 임플(네트워크 요청 및 컨버트) 

7. ViewController, Reactor

 

 

 

'apple > DesignPattern & Architecture' 카테고리의 다른 글

[Tuist] Mise Install  (1) 2024.08.31
Clean Architecture Swift #1  (0) 2022.09.23
[Swift] Coodinator Pattern  (2) 2022.07.07
[Swift] Command Pattern  (1) 2022.07.05
[Swift] Composite Pattern  (1) 2022.06.15
Comments