CH02 Clean Architecture 4 Layer
Last updated
Last updated
๊ฐ์์์ ํ๋ก์ ํธ๋ฅผ ๊ตฌํํ ๋ ๊ทผ๊ฐ์ผ๋ก ์ฌ์ฉํ๋ ์ค๊ณ๊ตฌ์กฐ์ธ 4๊ฐ์ ๊ณ์ธต์ด๋ค. ๊ทธ๋ฆฌ๊ณ ๊ฐ์์์ ์ฌ์ฉ๋๋ ์๋ํํฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ ๋ํ ์๋ด์ด๋ค.
๊ฐ์์๋ฃ๋ง ๋ด์๋ ์ ํํ ์ดํด๊ฐ ๊ฐ์ง ์์์ ์๋ ์ธ ๊ฐ์ง ํฌ์คํ ์ ์ฐธ๊ณ ํ๋ค.
์์ ๊ฐ๊ฐ์ ํฌ์คํ ์์ ๋ค๋ฃจ๊ณ ์๋ Layer ๊ตฌ๋ถ๋ค์ ๋์ํ ํ ์ด๋ฏธ์ง๋ค์ ์๋์ ๊ฐ๋ค.
ํฌ์คํ ๋ง๋ค ์ฝ๊ฐ์ฉ ์ฌ์ฉ๋๋ ์ฉ์ด๊ฐ ๋ค๋ฅธ ๋ถ๋ถ์ด ์๊ธด ํ๋๋ฐ ๊ณตํต์ ์ผ๋ก ๊ฒฐ๊ตญ ๊ฐ์ ์ด์ผ๊ธฐ๋ฅผ ํ๊ณ ์๋ค.
๊ฐ ๊ฐ๋ ์ ๋ํด์ ๋์ ๋ง๋ก ํ์ด์ ๋ค์ ์ ๋ฆฌ๋ฅผ ํด๋ณด์.
์ผ๋จ Layer ๋ค์ ๊ตฌ๋ถ์ ๋ํด์ ์์๋ณด๊ธฐ ์ ์ Layer ์์ฒด์ ๋ํ ์ ์๋ฅผ ํด์ผํ๋ค. ํฌ์คํ ์ ์ด๋ฏธ ์ ๋ฆฌ๊ฐ ์ ๋์ด ์๋๋ฐ ๋จ์ํ๊ฒ ํํํ์๋ฉด Layer ๋ Architecture ๋ฅผ ๊ตฌ์ฑํ๋ ๊ฐ๋ ์ด๋ค. ๋ ๋ฆฝ๋์ด ์์ผ๋ฉด์ Architecture ์ ๊ตฌ์ฑ์ ํฌํจ๋๊ธฐ ์ํด์ ํน์ ํ ์ฑ ์์ ์ง๋ ๊ฐ๋ ์ ์ธ ๊ตฌ๋ถ ๊ณ์ธต์ด๋ค.
Architecture Letโs start with the basics: what is app architecture? App architecture is the logical way we organize our projects and how the various components interact with each other to fulfill the business requirements. We want to follow standards and make it easy to identify the components that weโll need to develop features in our codebase. The way we establish the relationship and interactions between these components can reduce or add complexity to our projects, which has a significant impact on the teamโs productivity.
Layers Now that we know what architecture is, letโs define layers. Layers are the components that compose your architecture. We can define these by assigning a specific responsibility to them. We should keep these layers simple, yet isolated enough to achieve a maintainable codebase.
๊ฐ ๊ตฌ์ฑ์ ๊ดํด์๊น์ง ์ธ์ธํ๊ฒ ๋์ํ๊ฐ ๋ ๊ฒ์ ์๋ ๊ทธ๋ฆผ์ด ๊ฐ์ฅ ์ข์๋ค.
๊ธฐ์กด์ ๋ค๋ฅธ ๋ ํผ๋ฐ์ค์์ ์์๋ดค๋ ์๋ฃ๋ค๊ณผ ๋น๊ตํ์๋ Application Layer ๋ถ๋ถ์ด ์กฐ๊ธ ๋ค๋ฅด๋ค. ์ผ๋จ ๊ฐ์์์๋ ์ ๋ ๊ฒ ์ฌ์ฉํ๋ค. ๊ฐ์๋ฅผ ๋ชจ๋ ๋๋ด๋ฉด ๋ค ๋ค์ด๊ฐ๋ณด์ง ์์๋ ๋ชจ๋ ํ์ ํ๊ณ ์์ด์ผํ ๋ด์ฉ์ด๋ค
ํ์ตํ ๊ฒ์ ๊ธฐ๋ฐ์ผ๋ก ์๋ ๊ทธ๋ฆผ์ ๋ง๋ค์๋ค. ๊ฐ ๊ตฌ์ฑ๊ณผ ์ธ๋ถ ํญ๋ชฉ์ ๋ด์ฌํ ํ์. ์ฐธ๊ณ ๋ก ๊ฐ์์์ ๊ท์ ํ Application Layer ๋ ์๋ ๊ทธ๋ฆผ์์ ์๋ตํ๋ค.
Application Layer ๋ ๋ค๋ฅธ Layer ๋ค๊ณผ ์ํธ์์ฉ ํ๋ค๊ธฐ ๋ณด๋ค๋ ์ดํ๋ฆฌ์ผ์ด์ ์ ์ญ์ ์ ์ฉ๋๋ ์์์ ๋ํ Layer ์ด๋ค. ๋ฐฑ์๋์์ ์ฌ์ฉํ๋ AppConfig ํจํค์ง์ ์ฐ์๊ณผ ์ญํ ์ด ์์ ํ ์ผ์นํ๋ค.
์ฌ๊ธฐ์ UI Widget ๊ณผ State Management ์ฌ์ด์ ์ํธ ์์ฉ์ด ๊ณง view ์ viewModel ๊ฐ์ ์ํธ์์ฉ์ด๋ฉฐ ๋ณต์ต์ ์ํด ์๋ ๊ทธ๋ฆผ์ ๋ค์ ๋ณด์.
๊ตฌํ ํ๋ค๊ฐ ์ ๊น์ฉ ๋งํ๋๋ผ๋ ํ์ตํ๋ ๊ฒ์ ๋ณด๊ณ ๊ตฌํ์ ํ๋ฉด ๊ทธ๋ง์ด๋ค. ๋ฌ๋ฌ ์ธ์ฐ๋๊ฒ ์ค์ํ ๊ฒ์ด ์๋๊ณ ์ ๋ ๊ฒ ๊ณ์ธต์ ๋๋๋ ์ด์ ์ ๋ํด์ ์๊ณ , ๊ณ์ธต์ ๋๋๋ ๊ณผ์ ์์ ์ด๋ค ๋ฐฉ์์ผ๋ก ์ฒ๋ฆฌํ๋์ง์ ๊ทธ ๊ณผ์ ์์ ์ด๋ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋์ง ๋ฑ์ ๋ํด์ ์ธ์งํ์.
๊ฐ์์์๋ ์๋ฌ ์ฝ๋์ ๋ํด์ ๋ ์ ์ฒ๋ฆฌํด ๋์๋๋ฐ, ๋์ ํ๋ก์ ํธ์์๋ ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌํ ๊ฐ๋ฅ์ฑ์ด ์ปค์ ์ค์ต์์๋ ์๋ตํ๋ค.
์ผ๋จ ๊ฐ์ธ์ ์ผ๋ก๋ ์ธ ํฌ์คํ ์ค ๊ฐ ๊ฐ์ฅ ๋ณด๊ธฐ์๋ ์ข์๋ ๊ฒ ๊ฐ๋ค. ๋๋ฌด ์์ธํ ๋๋ ๋๋ฌด ๋จ์ํ ๋ฌ์ฌํ์ง ์์ผ๋ฉด์๋ ์ ํํ๊ฒ ๊ฐ Layer ์ ์ญํ ๊ณผ ๊ฐ Layer ์ ์ํ๋ ๊ฒ๋ค์ ์ญํ ๋ค์ ์ค๋ช ํ๊ณ ์์ด์๋ค.
์ด ํฌ์คํ ์ ๋์จ ๊ทธ๋ฆผ์ธ๋ฐ ์์ฌ์ด ์ ์ Layer ์์ฒด๋ง ์ค๋ช ํ์ผ๋ฉด ์ข๊ฒ ๋๋ฐ ์ผ๋ถ ๊ฐ๋ ์ด Bloc ์ ์์กด์ ์ด๋ค.
๊ฐ Layer ๊ฐ ์ค์ ๋ก ์ด๋ป๊ฒ ๊ตฌํ๋๋์ง์ ๋ํด์ ํ์ตํ๋ค. ๋ฅผ ์ฒจ๋ถํ๋ค.