- ์ฝ๋์ Architecture๋ Clean Architecture๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ค.
- Multi Module ๊ตฌ์กฐ๋ก ๊ตฌ์ฑํ๋ค.
- Module์ ๊ตฌ์กฐ๋ ๊ฐ Repository์ Readme์์ ํ์ธํ ์ ์๋ค.
- MVVM ํจํด์ ์ฌ์ฉํ๋ค.
- SAA ํจํด์ ์ฌ์ฉํ๋ค.
- ViewModel(Presentation Layer)์๋ ์๋๋ก์ด๋ ํ๋ ์์ํฌ ๊ด๋ จ ์ฝ๋๊ฐ ์์ด์ผํจ
- import android.* ์ฝ๋๊ฐ ์๋๋ก ์ ์ง(AAC๊ด๋ จ ์ฝ๋ ์ ์ธ, android.arch.*)
- https://medium.com/androiddevelopers/viewmodels-and-livedata-patterns-antipatterns-21efaef74a54
- ๋ค๋ง ๋ฐ์ดํฐ์ ํด๋น๋๋
R.string.xxx,R.dimen.xxx,R.color.xxx๋ค์ ์ฌ์ฉํ ์ ์๋๋ก ํจ- (
R.id.xxx,R.layout.xxx๋ ๋ถ๊ฐ)
- (
SavedStateHandle์ ์์ฑ์์ ์ฒซ๋ฒ์งธ์ ์์นํ๋ค.
Do
@HiltViewModel
class XxxViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val getFooUseCase: GetFooUseCase,
) : ViewModel()Do not
@HiltViewModel
class XxxViewModel @Inject constructor(
private val getFooUseCase: GetFooUseCase,
savedStateHandle: SavedStateHandle,
private val getBarUseCase: GetBarUseCase,
) : ViewModel()
@HiltViewModel
class XxxViewModel @Inject constructor(
private val getFooUseCase: GetFooUseCase,
private val getBarUseCase: GetBarUseCase,
savedStateHandle: SavedStateHandle,
) : ViewModel(): MVVM์ ViewModel์์ ์ด๋ฒคํธ๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ 6๊ฐ์ง
์ด๋ฒคํธ ์ด๋ฆ์ {ํ์}-{๋์}-{๊ฒฐ๊ณผ} ์์์ ์ด๋ฆ ๊ท์น์ ๊ฐ์ง๋ค.
object ShowCarInfo: Event() // ํ์: ๋ณด์ฌ์ค๋ค, ๋์: ์ฐจ๋ ์ ๋ณด
object UploadImageSuccess: Event() // ํ์: ์
๋ก๋ํ๋ค. ๋์: ์ด๋ฏธ์ง, ๊ฒฐ๊ณผ: ์ฑ๊ณต- Event์ ์๋ฏธ์ ๋ฐ๋ผ ๋์ฌ์ ํํ๋ ์์ ๋กญ๊ฒ ์ฌ์ฉํ๋ค. (๊ณผ๊ฑฐํ, ํ์ฌํ)
- Success, Complete์ ๊ฐ์ด ์๋ฏธ๊ฐ ์ด์ค์ ์ผ ๋์๋ ๊ธฐ๋ํ๋ ๋์์ ๋ฐ๋ผ ์ ์ ํ ์ด๋ฆ์ ์ ํํ๋ค.
- ํด๋์ค๋ ๊ฐ ํ๊ฐ์ usecase๋ฅผ ๊ฐ๋๋ค.
- ํด๋์ค๋ช ์ xxxUseCase ์ ๊ฐ์ด ๋ช ๋ช ํ๋ค.
- List๋ฅผ ๊ฐ์ ธ์ค๋ UseCase์ ์ด๋ฆ์ GetXXXListUseCase์ ๊ฐ์ด ์ ์ํ๋ค.
- ํจ์์ ๊ฒฝ์ฐ getXXXs()๋ก ์ ์๋๋ ๋จ์๋ฅผ ๊ฐ์ ธ์ค๋ UseCase์ ํผ๋์ ์ฐ๋ ค๊ฐ ์๊ธฐ๋๋ฌธ์ UseCase์ด๋ฆ์ List๋ฅผ ๋ถ์ธ๋ค.
- ๋ง์ฝ Room DB๋ฅผ ์ฌ์ฉํ๋ domain ํด๋์ค์ NonNull์ธ ํ๋๋ฅผ ์๋ก ์ถ๊ฐํ๊ฒ ๋๋ค๋ฉด Local Class์์๋ ์ด์ฉ์์์ด Nullable๋ก ์ ์ธํ๊ณ mappingํ ๋ default value๋ฅผ ์ง์ ํ๋ ๋ฐฉ๋ฒ์ผ๋ก ๊ตฌํํด์ผ ํจ
- ์)
- User์ email์ด ์ถ๊ฐ๋์ด์ผํจ
- email์ด NonNull์ด๊ธฐ๋๋ฌธ์ UserLocal์ ํ๋๋ฅผ ์ถ๊ฐํ ๋ email์ NonNull๋ก ์ ์ธํด์ผ ํ ๊ฒ ๊ฐ์ง๋ง
- ๊ธฐ์กด์ DB์ ์ ์ฅ๋์ด ์๋ ๋ฐ์ดํฐ์๋ email ๊ฐ์ด ์์ผ๋ฏ๋ก ๊ธฐ์กด์ ์ ์ฅ๋ db๋ฅผ toData()๋ก ํ๋ ค๊ณ ํ ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํจ
- XXXLocal์ class๋ ์๋ก ์ถ๊ฐ๋ ๋ ํญ์ Nullable๋ก ๋ง๋ค๊ณ toData()๋ก mapping๋ ๋ ๊ธฐ๋ณธ๊ฐ์ ์ ์ธํด์ค์ผ ํจ
- Model์ ๊ฐ๊ฐ์ layer์ ๋ง๋ค์ด์ ธ์ mapping๋๋๋ก ๊ตฌ์ฑํ๋ค
- ์) User๋ผ๋ ๊ฐ๋ ์ model์ ๋ํ ๊ฐ๊ฐ layer์์์ ์ ์
data class UserResponseDto(){}
fun UserResponseDto.toDomain(): UserEntitydata class UserEntity(){}
fun User.toData(): UserResponseDto
fun UserEntity.toPresentation(): UserModeldata class UserModel(){}
fun UserModel.toDomain(): UserEntity