Skip to content

Latest commit

 

History

History
158 lines (103 loc) · 8.85 KB

DAGGER AND RX.md

File metadata and controls

158 lines (103 loc) · 8.85 KB

DAGGER

  • What is the use-case of @BindsInstance Annotation?

  • What is the use-case of @Module Annotation?

    • @Module is the Annotation used on the class for the Dagger to look inside it, to provide dependencies. We may be declaring methods inside the module class that are enclosed with @Provides annotation.
  • What is the use-case of @Provides Annotation?

    • @Provides annotation is used on a method in Module class and can return / provide a Dependency object.
  • What is the use-case of @Component Annotation?

    • @Component is used on Interface or abstract class. Dagger uses this interface to generate an implementation class with fully formed, dependency injected implementation, using the modules declared along with it. This generated class will be preceded by Dagger. For example if i create an interface named ProgramComponent with @Component annotation, Dagger will generate a Class named 'DaggerProgramComponent' implementing the ProgramComponent interface.
  • What is the use-case of @Scope Annotation?

    • @Scope is an annotation used on Interface to create a new Custom Scope. A Scope declaration helps to keep single instance of a class as long as its scope exists. For example, in Android, we can use @ApplicationScope for the object to live as long as the Application is live or @ActivityScope for the object to be available till the activity is killed.
  • What is the use of Qualifier in Dagger?

    • We are often in a situation where we will be needing multiple objects with different instance values. For example, we need declare Student("Vamsi") and Student("Krishna"). In such case we can use a Qualifier to tell Dagger that we need multiple instances of same class. The default implementation of Qualifier is using @Named annotation, for eg., @Named("student_vamsi") and @Named("student_krishna") If we want to create a Custom Qualifier we would be using @Qualifier to declare a custom Qualifier interface.
  • What is the use-case of @Inject Annotation in Dagger?

    • @Inject annotation is used to request dagger to provide the respective Object. We use @Inject on Constructor, Fields (mostly where constructor is not accessible like Activities, Fragments, etc.) and Methods.

RXJAVA

  • What is an Observable in RXJava2?

    • An Observable simply emits the data to those which subscribed to it. All the emission is done asynchronously to the subscribers. A simple Observable can be created as follows:
    // RxAndroid Tutorial - Adding Observable
    Observable<String> stringObservable = Observable.just("Hello Reactive Programming!");
  • What is an Observer in RXJava2?

    • Observer consumes the data emitted by the Observable. To do this, Observer needs to subscribe to the Observable. Example shows how to create an Observable in RxJava2.
    // RxAndroid Tutorial - Adding observer
    Observer<String> stringObserver = new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
            }
    
            @Override
            public void onNext(String s) {
                Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
            }
    
            @Override
            public void onError(Throwable e) {
            }
    
            @Override
            public void onComplete() {
            }
        };
  • How to Subscribe / Unsubscribe in RXJava?

    • We can make an Observer to subscribe to Observable as follows:
    // RxAndroid tutorial - observer subscribing to observable
    stringObservable.subscribe(stringObserver);
  • Map vs FlatMap

    • Map transforms the items emitted by an Observable by applying a function to each item.

    image

    • FlatMap transforms the items emitted by an Observable into Observables.

    image

  • What are the different types of Observables in RxJava?

    • Single
    • Maybe
    • Completable
    • Observable
    • Flowable
  • What is a Single in RxJava?

    • A Single in RxJava is an Observable which emits only one item if completed or returns error.
  • What is Maybe in RxJava?

    • A Maybe in RxJava is used when the Observable needs to emit a value or a no value or an error.
  • What is Completable in RxJava?

    • A Completable in RxJava is an Observable which just completes the task and does not emit anything if completed. It returns an error if anything fails. It is similar to reactive concept of runnable.
  • What is Back Pressure in RxJava?

    • Back Pressure is the state where your observable (publisher) is creating more events than your subscriber can handle.
  • What is Flowable in RxJava?

    • A Flowable in RxJava is used when the Observable emits more data than the Observer can consume. In Other words, Flowable can handle back pressure where as an Observable cannot.
  • What is a Cold Observable?

    • A Cold Observable is an Observable that does not emit items until a Subscriber subscribes. If we have more than one Subscriber, then the Cold Observable will emit each sequence of items to all Subscribers one by one.
  • What is a Hot Observable?

    • A Hot observable is an Observer that will emit items
  • List RxJava operators.

    image

    Learn more here

  • Hot Observables vs Cold Observables

  • Explain about reactive programming?