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

Notification Observer Error In Swift

I'm using this IAP implementation guide and when a purchase is final, it posts a notification using this code: NotificationCenter.default.post(name: NSNotification.Name(rawValue: IAPHelper.IAPHelperPurchaseNotification), object: identifier) The…
Dave G
  • 12,042
  • 7
  • 57
  • 83
0
votes
1 answer

Data pull and push

I am writing a .NET window service which schedules job in certain interval. I am using QUARTZ for scheduling. A job will do 2 tasks: Pull data using some SDK from one data source. Push retrieved data to some other data source using REST…
Abhay
  • 928
  • 1
  • 10
  • 28
0
votes
1 answer

Observer Pattern not working on Ruby

I implemented this example below for use of the Observer Pattern on Ruby. I tried follow this, but didn't work. require "observer" class AAnyClass extend Observable changed notify_observers self end module AnObserver extend self def…
rplaurindo
  • 1,277
  • 14
  • 23
0
votes
3 answers

Connecting a form to a Javascript Object (and other best practice advice)

I've been using javascript to do lightweight functionality on sites for years - DOM manipulation etc - but just now im beginning to investigate using it to do a lot more of the heavy lifting (in combo with PHP). I've only just started getting into…
Laurie
0
votes
0 answers

GreenDao - Android - How to listen to DB change using GreenDao

I'm using GreenDao 3 and I'd like to know what is the URI to be used to listen to DB changes. I'm using this code: Uri uri = Uri.parse("content://" + BuildConfig.APPLICATION_ID +…
Douglas Fornaro
  • 2,017
  • 2
  • 22
  • 30
0
votes
2 answers

C# - How to react on an Event raised in another class?

I've Got 2 classes: One Service which creates a FileSystemWatcher that fires an event when the watched File is saved by Word. And one UserControl that has got some functions I need to execute when the SaveEvent is fired. How can I react to the…
Max T
  • 25
  • 9
0
votes
0 answers

What does an arrayList hold in it

So, I have created 2 interfaces One is called Observer and the other one Subject Observer contains update() method and Subject contains Boolean registerObserver(Observer o), Boolean removeObserver(Observer o) and void notifyObservers(). When I need…
P.Mit
  • 1
0
votes
1 answer

In MVC, one or multiple Model/Controller classes?

In a context of a multiple window application using MVC: In the Model layer, in order to implement the Observer pattern, should I use one Subject class and have every other Model class use it in order to notify observers? Or should I create…
0
votes
1 answer

Replace observer pattern with RxJava in Android

I have started learning about RxJava and RxAndroid. I would like to replace my observer pattern with RxJava. The observer pattern is similar to Android LocationManager class that has register and unregister methods. The "observable" class (not…
0
votes
1 answer

c++ static observer class

I have two programs: a server and a client class client { private: Network net; Gui gui; }; Here's the Network class class Network { public: void receivePacket(packet) { Protocol::readPacket(packet) } }; Here's…
Coodie_d
  • 35
  • 6
0
votes
0 answers

Java Swing MVC/Observer: GUI not updating

I'm building a Java program using the MVC/Observer pattern and have managed to get the update method in my View (Observer) class logging changes from my Model (Observable) class. The first 3 components below are JTextFields which are correctly being…
0
votes
0 answers

Surpress Observer in PHP

I am working on a pair of services that will update two systems through REST API calls. The first is for location 1, executing update calls on classes that make use of the observer pattern in php, to trigger an update service. This update service…
brian
  • 1
0
votes
2 answers

Ansestors to parents communication in react

I want to create a component with only one event and place it inside an ancestor of any given level (child or grandchild or deeper), and when the event triggers the parent of this ancestor will act (eg. alert("I am "+parent.name+" and one of my…
0
votes
2 answers

Release a listener / observer in Objective-C?

I'm not sure when it's the right moment to RELEASE a listener object. I have a object A that uses NSURLConnection's initWithRequest method to retrieve some URL. initWithRequest requires a delegate to listen after the events of dataReceived... So…
Giorgio
  • 13,129
  • 12
  • 48
  • 75
0
votes
1 answer

Alternative to singleton pattern in Java other than dependency injection or observer

I am making a JavaFX application and which has four root controllers. Each of these controls the view on a tab. There is no controller for the tab selector as it has no functionality other than to select which of the four views to show. These…
Matt
  • 688
  • 5
  • 15