You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
위에서 코드 라인별 리뷰를 남긴것처럼 suspend와 Dispatchers.IO사용을 잘 해서 비동기적으로 처리 잘 했습니다
Dispatchers.IO를 이용해 작업이 일어나는동안 메인스레드(ui스레드)를 차단하지 않게 잘 했어요
레포지토리를 사용하게되면 뷰모델은 레트로핏, DB, SharedPreference등 여러곳에서 오는 데이터를 신경 쓰지 않고 뷰모델 자체의 일만 하면 됨 (코드의 의존성)
예를 들어 내가 SharedPreference 저장하는 로직이 이 액티비티 말고도 다른곳에 있음. 그런데 RepositoryImpl에서 "memo"라는 값을 바꾸고싶음. 그러면 레포지토리의 구현부에있는 "memo"만 한번에 바꾸면 되겠죠? SharedPreference에 저장하는 로직도 여러곳에 쓸 필요없이 레포지토리 하나를 가져와서 한번에 관리 가능.
나중에 테스트 코드 작성할때 layer를 나눠서 데이터가 원하는대로 잘 받아졌는지 테스트할 수 있습니다 (activity<->viewmodel 사이 뿐 만 아니라 viewmodel <->repository 사이도 가능)
getSharedPreferences view에서 만들고, 그걸 ViewModelFactory를 통해 레포지토리에 넘겨주는 코드는 너무 좋습니다. (context 자체를 넘기는게 아니라서)
딱 하나 아쉬운건 getSharedPreferences를 MainActivity의 context로 만들었는데, 이렇게되면 MainActivity의 context를 계속 참조하고있습니다.
만약 MainActivity 종료후 BActivity실행. 여기서도 해당 레포지토리를 사용한다고 해봅시다.
case 1 ) RepositoryImpl(sharedPreference) 이 코드를 BActivity에서 또 실행한다. -> 이미 레포지토리 만들어뇠는데 또 만들어야해? 같은로직인데
case 2) MainActivity에서 만든 RepositoryImpl를 BActivity로 넘겨주자 -> MainActivity가 종료되어도 MainActivity의 context가 참조되고 있기 때문에 메모리에서 사라질 수 없음 (가비지컬렉터)
추천 방법 ) getSharedPreferences를 application에 싱글톤으로 선언하고 그걸 가져오자
이유 -> application은 어플이 실행되어있는동안 항상 살아있음.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
화면은 editText랑 savedButton 두 개로 구성했습니다.
editText에 값이 있을 시 viewModel에서 데이터 저장 로직을 처리하게 했고 (updateValue), 저장하거나 데이터 로드할 땐 Repository 이용해서 sharedPreference와의 직접적인 터치는 Repository 사용하였습니다.
의문점 1.
제 코드가 이 조건을 만족시킨 건지? (MyViewModel 의 updateValue와 init 부분)
의문점 2.
Repository 패턴을 적용하는 이유가 무엇인지?