본문 바로가기

Android/Architecture

[Android] Modular Architecture 개념 정리

728x90

처음 학습하면서 작성한 글입니다. 필요시 추후 내용을 수정할 예정입니다.

틀린 부분이 있으면 언제든 지적해주면 감사하겠습니다 :)

본 포스팅 작성에 참고한 블로그는 맨 하단에 작성해두었습니다. 


 

클린 아키텍처 구조를 공부하면서, 모듈을 나누어 구현하는 구조에 대하여 관심을 갖게 되었다.

Modular Architecture 라고 구글링을 해보니, 해외 자료들만 나오기도 하고..

클린 아키텍처 처럼 규격화(?) 되어있는 것이 아니라 찾아본 자료를 토대로 정리를 해보고자 한다.


우선,

Modular Architecture 란 간단히 말해서.

 

하나의 거대한 구조의 APP 을 만드는 대신, 여러개의 작은 단위의 Module 을 만들어서 하나의 앱을 만드는 것.

 

이라고 생각하면 된다.

 

이것에 대해서 인상깊게 설명해 둔 블로그가 있어서 그 글을 가져와보았다.

 

Here A single Avenger can be anyone Tony Stark, Hawkeye, Dr.Strange and they all do some specific thing right but when they come together they are a team and that team is called Avengers.

same way, There can be N number of independent Modules and each module can be used for some specific task like login or onboarding but when all of these modules we merge, that will form as a single unit an App (a beautiful one).

(출처 : https://medium.com/native-mobile-bits/modular-android-app-architecture-build-to-scale-d6f402cbd93a)

 

클린 아키텍처도 Presentation, Domain, Data 3개의 계층.

즉, 3개의 모듈로 나누어서 구조를 만들어둔 것이기 때문에 모듈러 아키텍처로 구현한 한 방법이라고 생각한다.

 

모듈로 나누는 기준에 대해서는 딱히 정해진 것이 없다.

회사에 맞춰서, 프로젝트에 맞춰서 적당한 모듈을 나누어서 구조를 설계하면 된다고 생각한다.

참고한 블로그들의 글을 보면 모듈로 나누는 것에 대해서 모두 다른 방식으로 구조를 설계한 것을 볼 수 있었다.

 

예로들자면,

 

  • Library Module, Feature Module, App Module.
  • App Module, Core Module, Feature Module, Commons Module, Library Module

같은 구조로 말이다.

 

이렇게 다른 형태로 모듈을 구분해 두었지만,

결과적으로 기능별로 모듈이 나누어진 느낌을 볼 수 있었고, 모듈을 사용하는 공통된 이점들이 있었다.

 

  1. 유지/관리가 용이하다.
  2. 모듈의 추가/제거가 편리하다. (재사용성이 높다)
  3. Side Effect 를 줄일 수 있다.
  4. 빌드 시간이 빠르다.
  5. 협업 시에 유용하다.

다양한 장점들이 있었지만, 전체적으로 보았을 때  Module 이 독립적이기 때문에 얻을 수 있는 이점들이 많았다.

필자도 위에 작성한 장점들 때문에 Clean Architecture . 나아가 Modular Architecture 에 대해 공부하고자 하였다.


그렇다면, 

어떠한 방식으로 모듈을 나누어서 사용해야 할까?

 

필자가 학습을 위해 찾아본 자료 중, Google I/O 2019 의 영상이 잘 표현하고 있는 것 같아서 이미지를 가져와 보았다.

 

출처 :  https://www.youtube.com/watch?v=PZBg5DIzNww  
출처 :  https://www.youtube.com/watch?v=PZBg5DIzNww  

 

위의 두개의 이미지만 보아도, 어떤 방식으로 모듈을 나눠서 사용해야할지 느낌이 올 것이라고 생각한다.

기준별로(기능, 화면이 될 수 있고 그 외 기준이 있을 수 있다.) Module 을 나누고, 해당 Module 에서 공통된 부분이 있다면 다시 하위 Module 로 빼내어 필요한 모듈에 주입시켜주는 형식으로 사용하면 되는것으로 보인다.

 

출처 : https://developer.android.com/jetpack/guide

 

Google Developer 에서 확인해보면 위의 이미지와 같이 일반적인 앱 아키텍처에 대하여 작성해 둔 것이 있는데, 이것은 클린 아키텍처와 동일하다.


따라서, 필자는 클린 아키텍처 구조 안에서 모듈을 나눠 적용시키는 방식으로 예제를 만들어보려고 한다.

큰 틀은 Presentation, Domain, Data 의 3 계층을 유지하되, 각 계층에서 나눌 수 있는 부분을을 모듈로 나누어서 사용하면 되지 않을까 생각한다.

 

Presentation 모듈에서 나누고자 한다면

화면(Activity)에 따라서 모듈을 나누고, 필요한 하위 모듈인 Domain, Data 를 참조해서 사용하면 될 것으로 보이고,

 

Domain, Data 모듈에서 나누고자 한다면

사용하는 데이터의 종류에 따라서 모듈을 나눈 후에, 해당 데이터를 사용하는 다른 모듈에서 참조하도록 하면 되지 않을까 싶다.

 

Modular Architecture 를 사용한 예제는 GitHub 에 올려두었다.

https://github.com/HeeGyeong/ModuleArchitecture

 

GitHub - HeeGyeong/ModuleArchitecture

Contribute to HeeGyeong/ModuleArchitecture development by creating an account on GitHub.

github.com


본 포스팅 작성을 위해 참고한 블로그 입니다.

https://medium.com/ne-digital/a-cleaner-way-to-modular-architecture-in-android-2608795f09b6

 

A Cleaner way to Modular Architecture in Android

A custom built framework to initialise Android Modules

medium.com

https://medium.com/native-mobile-bits/modular-android-app-architecture-build-to-scale-d6f402cbd93a

 

Modular Android App Architecture (Build to scale)

Hi Everyone 😀 I am writing this blog, to sum up, my two cents on this Most heard combo of words “Modular App Architecture”

medium.com

https://proandroiddev.com/android-components-architecture-in-a-modular-word-7414a0631969

 

📚 Android Components Architecture in a Modular Word

Over years Android architecture evolved to support production-quality apps on any scale focused on helping developers to design robust…

proandroiddev.com

https://themach.tistory.com/47

 

[해석] 모듈식 안드로이드 앱 아키텍쳐를 구축하라 (1) (Google I/O'19)

Title: Build a Modular Android App Architecture Speaker(s): Yigit Boyar, Florina Muntenescu 1. 어떻게 모듈화된 안드로이드 앱 아키텍쳐를 구축할 것인가? 1) 왜 우리는 이를 구축해야하는가? (1) Sca..

themach.tistory.com

https://www.youtube.com/watch?v=PZBg5DIzNww 

 

728x90