룬아님의 취중코딩

(레포지토리 패턴) local과 remote 중 하나에서만 작동하는 기능이 필요할 때 본문

개발/안드로이드 개발

(레포지토리 패턴) local과 remote 중 하나에서만 작동하는 기능이 필요할 때

룬아님 2019. 10. 28. 16:45

레포지토리 패턴을 구현하면 하나의 데이터 소스를 상속 받아 local 데이터 소스와 remote 데이터 소스를 구현하게 된다.
완벽하게 같은 기능을 하는 경우에는 양쪽의 기능을 구현하면 되지만 local이나 remote에서만 사용되는 기능(예 : 북마크)은 어떻게 구현해야 할까라는 의문이 들었다.
우선적으로 들었던 생각은 해당 기능을 아예 다른 레포지토리로 분리하는 방법이였는데 유사한 기능을 가진 레포지토리를 2개를 만드는 것은 레포지토리 패턴을 사용하는 의도와 다르다는 생각이 들었다.

그러는 도중 구글 블루프린트의 이슈 중에 나와 비슷한 고민을 가지고 있는 이슈를 보게 되었다.

https://github.com/android/architecture-samples/issues/201

 

[question] Repository Pattern empty methods in read only remote data source · Issue #201 · android/architecture-samples

How can we handle cases where one of the resources lets assume student is read only from server end. In such cases we have saveStudents method in the interface which is being implemented only by th...

github.com

 

아직 확연하게 와닿는 답변은 없었지만

https://github.com/android10/Android-CleanArchitecture/blob/ae30300e1c2b1edbb096ad42ae66fc34c4979bb1/data/src/main/java/com/fernandocejas/android10/sample/data/repository/datasource/DiskUserDataStore.java#L41

 

android10/Android-CleanArchitecture

This is a sample app that is part of a series of blog posts I have written about how to architect an android application using Uncle Bob's clean architecture approach. - android10/Android-Clean...

github.com

해당 프로젝트에서

@Override public Observable<List<UserEntity>> userEntityList() {
  //TODO: implement simple cache for storing/retrieving collections of users.
  throw new UnsupportedOperationException("Operation is not available!!!");
}

사용되지 않는 기능을 UnsupportedOperationException으로 예외처리 하는 방법을 보게 되었다.

우선적으로 이 방법을 통해 구현할 예정이지만 다른 아이디어도 고민해 봐야겠다.

반응형
Comments