Questions tagged [observer-pattern]

A design pattern in which an object, called the subject, maintains a list of its dependents, called observers and notifies them automatically of any state changes, usually by calling one of their methods. It is one of the Gang of Four's behavioral design patterns. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

The Observer pattern (a subset of the publish/subscribe pattern) is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems.

This is one of the Gang of Four's behavioral , first published in Gamma et al.'s book "Design Patterns: Elements of Reusable Object-Oriented Software".

References:

1815 questions
0
votes
0 answers

Where is the implemantion of `Context.registerReceiver()`

I wanted to know how Google implemented the observer pattern for their broadcast receivers. So I dug into their code and I found a method definition and a implementation. Definition in class Context: @Nullable public abstract Intent…
winklerrr
  • 13,026
  • 8
  • 71
  • 88
0
votes
0 answers

AspectJ java throwing weird errors

I'm trying to implement the observer pattern into my program using AspectJ (not spring) and I tried to write the adding observer method but the compiler seems to complain after(Subject employee, Observer handler):…
Mocktheduck
  • 1,333
  • 1
  • 22
  • 43
0
votes
2 answers

Notify . change of ObservableProperties

I have a class with following properties : public class Member { private LongProperty version; private LongProperty id; private StringProperty name; private StringProperty surname; private StringProperty bornname; …
VANILKA
  • 634
  • 1
  • 13
  • 32
0
votes
1 answer

LocalDateTime.now() throwing exception when called in a JavaFX context with observer

I'm writing a JavaFX application where the FXController is an Observer to a Different class. I need to get the last time the observer received a notification to update. The problem is I'm trying to use java8 time API, with LocalDateTime and…
shawon13
  • 91
  • 9
0
votes
2 answers

Observer pattern specialisation

I'm trying to use the Observer pattern for some input stuff like so: class Observer { public: virtual void notify(Subject & o)=0; }; class Subject { public: virtual void register(Observer * o)=0; } I have two concrete Subjects (Mouse,…
Ian Young
  • 1,712
  • 1
  • 16
  • 33
0
votes
2 answers

c++ how to hide observer implementation

I am designing some kind of observer pattern for my project, the problem is I don't want my Observee derived classes exposing to public it's methods like attachObserver(...) or detachObserver(...). Only my "Observer" classes needs to access these…
kholm
  • 1
0
votes
2 answers

Observer pattern that has specific "observable/subscriber" relationship

I have been trying to make an base observer pattern that uses generic types to create a tightly coupled relationship between the observable object and its subscribers. Take for instance YouTube; a channel would be the observable object and the…
Jedi_Maseter_Sam
  • 753
  • 4
  • 24
0
votes
1 answer

Java Swing multithread management with observer pattern

My goal is to draw a rectangle and move it smoothly from left to right, using Observer pattern. I have a Model class, which is the Observable where I put the coordinates of the rectangle, and a Display class which is the Observer and perform…
0
votes
0 answers

Android Observable with singleton class

I have the following Activity A as an observer Activity B as an observer Singleton class C for media player as an observable. Singleton class is notifying the observers (Activity A & B) when the song is completed. However, only one of the…
RiyasMd
  • 35
  • 5
0
votes
1 answer

Using an observer pattern on objects that don't know about each other directly

Here are my Observer and Observable interfaces public interface Observable { void addObserver(Observer o); void removeObserver(Observer o); void removeAllObservers(); void notifyObservers(); } public interface Observer
jax
  • 37,735
  • 57
  • 182
  • 278
0
votes
1 answer

Node.js server sending info to ios app

I am new to backend programming but would like to try and put together the backend of an app I am building. I essentially am looking to implement an observer type programming pattern, just between the server and ios app. For instance two different…
dgelinas21
  • 641
  • 3
  • 9
  • 22
0
votes
3 answers

What is this line of code producing?

I have been studying the observer pattern from head_first_design_Patterns book. The scenario is this " there is an ArrayList named as observers and it has all the observers that are implementing the Observer interface. In the book,they are using a…
Haris
  • 764
  • 4
  • 9
  • 27
0
votes
1 answer

Combined and Filter Observable for Unique Keys to QueryFirebase

I'm working on an app where a contractor can say that they are "available" on specific days and each contractor has a "location". An employer can search for availability based off of location and availability. The location is based off of GeoFire.…
dhndeveloper
  • 311
  • 2
  • 15
0
votes
0 answers

c++ Observer pattern: Is it a sensible design to make subject to be an observer at the same time?

In observer pattern, subject notices a change to observer. But I also need subject to be notified by observer. I went something like this for the purpose: //Observer.h class Subject; class Observer{ public: void update(Subject* p_subject); …
Kevin
  • 1
  • 1
0
votes
0 answers

Need AI players in a card game to access others' cards

I'm programming a card game (of Uno / Mau Mau type) and my "problem" is as follows: The high level AI players can cheat by being able to check what cards the other players have in their hands. Two solutions come to my mind: 1) Add getters to…
Caroline
  • 33
  • 3