Skip to content

Instantly share code, notes, and snippets.

@OrenBochman
Last active October 31, 2018 14:46
Show Gist options
  • Save OrenBochman/3e7840b1fd8c14543fa0ab14bf6be7e5 to your computer and use it in GitHub Desktop.
Save OrenBochman/3e7840b1fd8c14543fa0ab14bf6be7e5 to your computer and use it in GitHub Desktop.
Android Architecture
public interface UseCase {
Response execute(Request request);
}
public interface UseCase {
void execute(Request request, Callback callback);
interface Callback {
onResponse(Response response);
}
}
public interface UseCase<Q, S> {
void execute(Q request, Callback<S> callback);
interface Callback<R> {
void onResponse(R response);
}
}
public interface UseCase<REQUEST, RESPONSE> {
Observable<RESPONSE> execute(REQUEST request);
}
import android.support.annotation.NonNull;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.Single;
import polanski.option.Option;
/**
Interfaces for Interactors. This interfaces represent use cases (this means any use case in the application should implement this contract).
*/
public interface ReactiveInteractor {
/**
Sends changes to data layer.
It returns a {@link Single} that will emit the result of the send operation.
@param <Result> the type of the send operation result.
@param <Params> required parameters for the send.
*/
interface SendInteractor<Params, Result> extends ReactiveInteractor {
@NonNull
Single<Result> getSingle(@NonNull final Option<Params> params);
}
/**
Retrieves changes from the data layer.
It returns an {@link Flowable} that emits updates for the retrieved object. The returned {@link Flowable} will never complete, but it can
error if there are any problems performing the required actions to serve the data.
@param <Object> the type of the retrieved object.
@param <Params> required parameters for the retrieve operation.
*/
interface RetrieveInteractor<Params, Object> extends ReactiveInteractor {
@NonNull
Observable<Object> getBehaviorStream(@NonNull final Option<Params> params);
}
/**
The request interactor is used to request some result once. The returned observable is a single, emits once and then completes or errors.
@param <Params> the type of the returned data.
@param <Result> required parameters for the request.
*/
interface RequestInteractor<Params, Result> extends ReactiveInteractor {
@NonNull
Single<Result> getSingle(@NonNull final Option<Params> params);
}
/**
The delete interactor is used to delete entities from data layer. The response for the delete operation comes as onNext
event in the returned observable.
@param <Result> the type of the delete response.
@param <Params> required parameters for the delete.
*/
interface DeleteInteractor<Params, Result> extends ReactiveInteractor {
@NonNull
Single<Result> getSingle(@NonNull final Option<Params> params);
}
/**
The refresh interactor is used to refresh the reactive store with new data. Typically calling this interactor will trigger events in its
get interactor counterpart. The returned observable will complete when the refresh is finished or error if there was any problem in the process.
@param <Params> required parameters for the refresh.
*/
interface RefreshInteractor<Params> extends ReactiveInteractor {
@NonNull
Completable getRefreshSingle(@NonNull final Option<Params> params);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment