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
2 answers

Javascript - Prototype: Event.observe on a form is not working for IE

I have this JS which gets a XML response from a service, its a True or a False, well the script should catch the submit and get the response from the service. The problem is that I see that its not working because when I do the submit, I see the XML…
BoDiE2003
  • 1,349
  • 6
  • 28
  • 41
0
votes
1 answer

How to practically use the Observer pattern in laravel?

So I am learning about design patterns and I am currently studying the Observer pattern. To implement it on a raw basis, I did something like this:
Rohan
  • 13,308
  • 21
  • 81
  • 154
0
votes
1 answer

Observer, Action Listener, KVO in iOS Swift

Okay, I have an issue with the addObserver function in Swift. How is that possible, if I change a value of an object A that object B reacts? (Without A knows B but B has a variable with a reference to A) for example here: class A { var willChange:…
Lirf
  • 111
  • 12
0
votes
2 answers

Changing Core Data Items crashes App

I am running into another problem with my Iphone App which I just can't solve myself. I implemented a kind of organizer functionality in my latest app. There one can create appointments which are displayed in a tableview and persisted in a…
Amandir
  • 679
  • 1
  • 7
  • 20
0
votes
1 answer

Using SwInject in conjunction with a central observer pattern

I am using SWInject to maintain dependencies in my app, and the Coordinator pattern to manage logic and dependencies. Can the SWInject be used in conjunction with a centralized push notification framework with multiple observers in different parts…
meow
  • 27,476
  • 33
  • 116
  • 177
0
votes
0 answers

Swift detect changes UILabel from Array

I need to detect changes to my UILabel. In my code i have in array which is getting updated via Socket IO. But the changes only appear when i scroll. I need that when the array changes, the label get updated directly. How can i get this working? in…
erwinnandpersad
  • 376
  • 5
  • 16
0
votes
1 answer

Angular 2 - EventEmmiter inside subscribe method

I am trying to create a "item-list" component to host a form that receives some data as input and send a http request to server, when receiving the response I would like to broadcast the new info to the parent that should work as a "list-component".…
Victor Carvalho
  • 1,610
  • 3
  • 14
  • 18
0
votes
1 answer

Observable do not receive the next value in angular2

In order to pass value between angular2 different components, I use different services injected into different components. In my PagesService component, I define a behavior subject and want to pass a value. import { Injectable } from…
0
votes
0 answers

Iterate through an ArrayList + Observer Pattern

I have recently tried programming various versions of Iterator and Observer Patterns in Java, but currently I'm stuck at the implementation of both in one project: What I'm trying to accomplish is to iterate through an ArrayList, which contains…
0
votes
1 answer

Delphi Push Notifications To Update Forms

I'm trying to figure out the best way to distribute state changes to multiple forms which make up an application. In my scenario, I have a number of hardware devices which are monitored by my application. As an example, one of the devices is a GPS…
weblar83
  • 681
  • 11
  • 32
0
votes
4 answers

Says I am overriding final method but I can't find final

I am trying to implement a Observer Pattern on Java. It won't compile because notifyAll() seems to be the problem here; Cannot override the final method from Object but I haven't put any 'final' nor 'static' in the code. What am I doing wrong…
younghak
  • 47
  • 1
  • 8
0
votes
1 answer

could not understand some codes in Observer pattern

This is the code: var Event=(function(){ var clientList={},listen,trigger,remove; listen=function(key,fn){ /*some code*/ }; trigger:function(){ var key=Array.prototype.shift.call(arguments); …
0
votes
1 answer

CDI - is the caller notified when an observer observes an event?

I am using CDI and want to know how the caller is notified that the observer has observed an event or didn't. If no observes act on that event, then I want to do something. I don't see this being documented anywhere in the documentation other than…
Walter White
0
votes
1 answer

What is the difference between the Observer and Subject-Observer patterns

While watching some videos on Channel 9 about the Reactive Extensions for .NET, someone asked whether the Reactive Extensions library is an implementation of the Observer pattern. The presenter then went on to answer by saying that the library is an…
0
votes
2 answers

Why isn't the correct data being received?

I wrote a program to learn and play with the observer pattern, but I'm having trouble with the data being printed out correctly. It should print out the data input at lines 7-9 in the paste, but instead it just prints 0,0,0. Main class public class…
Supetorus
  • 79
  • 2
  • 10
1 2 3
99
100