I need to perform some tasks on object1 when some state change happens on object2.
I was trying to use observable pattern in android, I mean to use Observer and Observable classes, so object1 implements Observer and object2 extends Observable. Unfortunately, object2 already extends from another class, so I can’t define it as an extension of Observable.
Is there another alternative to use this pattern? Maybe other classes that allow me to perform this behavior?
Thanks.
Simply add to
object2a field of typeObservableto which observers are added and on whichnotifyObservers()is called when something changes.This is what’s meant by “favor composition over inheritance”.