dimanche 30 juin 2019

Which Design Pattern should i use for notifying changes ? Java/Kotlin Android

Here's the situation, I am building an SDK for customers to be notified of three different touch states:

  1. Object Touched

  2. Object Touched Outside

  3. Object Touched Exit

I tried using the Observer Design Pattern, where the Observable sends updates to all the Observers which are the customers. however there are a few problems.

https://stonesoupprogramming.com/2017/10/28/observer-pattern-in-kotlin/

Following this design guideline is see that in order for customers to subscribe they will need to code the following:

val bob = Bob()
bob.addObserver(Customer1())



 class Customer1: Observer{

    val name = "Customer1"

    override fun update(o: Observable?, arg: Any?) {
      // Do your logic here
    }
}

This means customer when they integrate the SDK need to both declare a Class file called Customer1 with extended Observer.

Is there a way to simplify the process of having customers register as an Observer for our SDK's Observable? I'm not sure what sort of abstraction to implement.

Aucun commentaire:

Enregistrer un commentaire