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
1 answer

Eclipse @Observes in @Stateless bean compile error

I have a ListenerImpl which purpose it is to handle Events Asynchronously. to achieve this I use the following method. @Asynchronous public void handle(@Observes MonitorEvent pEvent){ //dostuff } The class itself is annotated…
Bgvv1983
  • 1,256
  • 1
  • 13
  • 27
0
votes
3 answers

Multithreading or observer pattern when waiting for dns lookup?

I'm designing a system in java which utilizes a dns lookup class. My question is, when calling the class's dnsLookup(), whether to do it in a new thread or use the observer pattern and let the dns class tell me when it's done. This isn't a problem…
Dennis S
  • 858
  • 1
  • 18
  • 32
0
votes
1 answer

error C2660: 'MouseListener::MousePressed' : function does not take 4 arguments

Im working on an c++ pseudo graphic button for a school assignment. I use the observer pattern. in Button.cpp: void Button::notify() { for (int iterator = 0; iterator < listeners.size(); iterator++) { …
Adi Gonen
  • 3
  • 3
0
votes
1 answer

Javascript MVC Two way binding Without Framwork dependency

I need a solution with a minimal library which helps me to track M<->V changes (two way binding). We have a constraint of libary size not more than 7kb. We are looking for good minimal code that helps to solve this problem. We have tried backbone…
0
votes
0 answers

Multiple notifyObserver

I'm working in a java project with Socket, MVC Pattern and Observer/Observable Pattern. I have to do a double notify from a Controller to a view like follow: this.game.notifyObservers(new InfoMessageType(InfoMessageTypeEnum.SHOWINITIALMMESSAGE,…
0
votes
1 answer

EcmaScript Object.observer is not notifying property changes

I an using ES6 classes plus Object.observer, using the MaxArt2501 implementation. I have this code below: const READY = Symbol("Ready"); const RUNNING = Symbol("Running"); class Foo { constructor() { this.value = 1; this.status…
Rafael Afonso
  • 595
  • 1
  • 10
  • 28
0
votes
2 answers

Observer pattern infinite loop

I have an situation when i have an Observer to be a also a subject. So let's image with have two entites A and B. When Changes occurs in A's Model other entites should know including B (C,D...Etc). When Changes occurs in B's Model other entites…
abdou amer
  • 819
  • 2
  • 16
  • 43
0
votes
2 answers

JFrame waiting for data reception to perform its task

I have two different and independent JFrame windows: DataFrame GraphFrame The first one is for the user to manipulate, with the input of different values and patterns to display on a graph presented in 2). The 1) sends specific values to 2) (array…
dgteixeira
  • 61
  • 9
0
votes
1 answer

Unable to insert objects of equal priority into ConcurrentSkipListSet

I am having an issue with a simplistic thread-safe implementation of the observer pattern using a ConcurrentSkipListSet to handle keeping track of observer priorities during insertion. The majority of observers will not have any special priority…
0
votes
0 answers

Any way to set observer order for Firebase?

I'm using the Objective-C API, though I would imagine that this question is valid regardless of language. I'm trying to write my code so that my app observes when child objects are removed from a particular node. When a child object is removed, I…
0
votes
0 answers

pass a variable from observer to controller

i have a controller (User controller), this is used to create update and delete a user from db. Within the UserObserver class after_save is been defined as a method in UserObserver after each save in db i have to call another application through…
0
votes
1 answer

Java Observer does not update when GUI window is not on top

I searched but I didn't find any solution to a similar problem. I have a problem with an Observer/Observable pattern. The Observable is implemented at a class called "firstmap" and the classes are: class ObservableValue extends Observable{ …
Thomasp
  • 1
  • 2
0
votes
0 answers

How to repeatedly update an instance variable as from `MouseEvent` javafx?

I am using the Observer patter, and i would like to be able to update all observers that the xValue of the subject class has change, using the xValue from the MouseEvent so basically when the user clicks on the scenethe xCompchanges and the…
0
votes
0 answers

C++ - Function ponter or Observer class

In a specific program I'm coding, I'm having trouble to decide whether to use function pointer or an Observer-pattern class. There is a struct called Universe which runs n-body simulations. Occasionally there are some collision between some of its…
Hydren
  • 363
  • 2
  • 11
0
votes
1 answer

Java : how to use the observer design pattern to update all instances of a class

So I have a film class that has the data members : id, name, genre, type, and price. Is it possible for me to use the observer design pattern to update the price of all these films. So i want to select an option to add the promotion all the films to…
SG_2894
  • 29
  • 2
1 2 3
99
100