diff --git a/app/src/main/java/com/example/sprout/refactor/model/BaseModel.java b/app/src/main/java/com/example/sprout/refactor/model/BaseModel.java new file mode 100644 index 0000000..435c1ce --- /dev/null +++ b/app/src/main/java/com/example/sprout/refactor/model/BaseModel.java @@ -0,0 +1,42 @@ +package com.example.sprout.refactor.model; + +import io.reactivex.Observable; +import io.reactivex.subjects.BehaviorSubject; +import io.reactivex.subjects.Subject; + +/** + * Entityを管理するクラスの基底クラス + * :Entity + * :CRUDに必要なParams + * Created by matsumoto_k on 2017/12/19. + */ +public abstract class BaseModel { + protected final Subject entitySubject = BehaviorSubject.create().toSerialized(); + protected final Subject errorSubject = BehaviorSubject.create().toSerialized(); + + public abstract void create(Params params); + + public abstract void read(Params params); + + public abstract void update(Params params); + + public abstract void delete(Params params); + + /** + * Entityを保持するSubjectをObservableに変換して返す + * + * @return Observable + */ + public Observable getEntityObservable() { + return entitySubject.hide(); + } + + /** + * Errorを保持するSubjectをObservbaleに変換して返す + * + * @return + */ + public Observable getErrorObservable() { + return errorSubject.hide(); + } +}