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

Weird behavior using the Observer pattern

Ok, so I have an application that reads another processes memory. I initially had multiple scanning threads for the various areas I needed to read. This was processor intensive so I decided to go with the observer pattern. All was well except that…
hawkstrider
  • 4,141
  • 16
  • 27
0
votes
0 answers

FireMonkey observers

I have two custom controls tDescendant1 and tDescendant2 that are descendants of other custom control tAncestor. tAncestor handle some events as MouseDown, Click, etc. tDescendant1 and tDescendant2 also must handle the Click event, so they, in turn,…
user2383818
  • 709
  • 1
  • 8
  • 19
0
votes
2 answers

Observer pattern - Does observable needs to be always abstract?

I am new to design patterns , I am learning Observer pattern for that I went to many sites ,where I found the below UML diagram So my question is on the UML or class design.If the purpose of the observer pattern is to notify the observers about…
vicky
  • 2,119
  • 4
  • 18
  • 32
0
votes
1 answer

using observer pattern to model notifications to subscribers

This might be a little long question but i try to keep it as small as possible and try to put it in the best way i can. I have reading about design patterns and found observer pattern very intresting. i searched for its practical application and…
anekix
  • 2,393
  • 2
  • 30
  • 57
0
votes
1 answer

Javafx bind SetProperty to a callback that produce a set from an observable

I have a SetProperty and a function that produces a Stream. Stream generatePoints(Point p) { // ... } ObjectProperty selectedPointProperty() { // ... } SetProperty generatedPoints = new…
charlieh_7
  • 334
  • 3
  • 12
0
votes
2 answers

Why do some methods belong to the subject/observer interface, while others to the subject/observer concrete subclass?

From Design Pattern by Gang of Four Why are field observers, and methods Attach, Detach and Notify are in the interface Subject, while methods GetState and SetState and field SubjectState are in the concrete subclass ConcreteSubject? Why are the…
Tim
  • 1
  • 141
  • 372
  • 590
0
votes
5 answers

Struggling to understand observer patterns

I've read as much as I can about observer patterns but I am failing to fully understand what/when it would be used. Can anyone explain this to me?
anon
0
votes
1 answer

Notify Users on User Defined Events on Data changes on server

I have a node.js webservice with 10k users.each user can monitor price changes of 1k items(realtime or every second). my problem started here: each user can listen 4 event : start/stop/higher/lower for each item. when event fired i need to send sms…
0
votes
1 answer

Javascript Observer pattern can not access private property

The following code below is javascript obeserver pattern, but when it execute "subject.subscribeObserver(observer1);", error occurs that "can not read property push of undefined", it seems that I can not access subject.observers. Why does this…
Jerry
  • 91
  • 1
  • 1
  • 7
0
votes
1 answer

javascript observer pattern help in my code

Please help i m not getting what is mistake in my code. This is regarding observer pattern in js. Getting error "Uncaught TypeError: Cannot read property 'push' of undefined". I think this error is because "observers" key is not created on the…
niraj17
  • 79
  • 7
0
votes
1 answer

calling external function in Proxy object (Javascript ECMAscript)

I am observing an object and want to call a function upon changing values. I could do it with Object.observe and would like to try simplify with Proxy. I cannot call an external function, cause it say undefined. How to trap an external function…
user305883
  • 1,635
  • 2
  • 24
  • 48
0
votes
1 answer

Java observer pattern for a GUI - distinguish between different events without typeof

I have a simple Controller object that that implements Observer (i.e. it is the observer) which listens for events from a Mouse object that extends Observable (i.e. it is the observee). So there can be multiple events in a Mouse object e.g. left…
user7533668
0
votes
1 answer

Design pattern in RESTful Android application

In my app, which has tabbled activity with four tabs [ tab1 | tab2 | tab3 | tab4 ]. Pic shown is not of my app, but to get a feel how it might look similar to although there are differences as mentioned here. Each tab is associated with a…
0
votes
2 answers

Android; Using a Service to subscribe/unsubscribe to an Observable object, good idea?

I have a requirement, whereby when a user clicks a button, then an object needs to be observed. When the user clicks that button again, the observation stops. My initial thought is to have the button bound to a method in the activity using the…
Jimmy
  • 16,123
  • 39
  • 133
  • 213
0
votes
1 answer

after_destroy display unscoped value with observer class in rails

I am trying to add to the activity canceled value with after_destoy in observer class, but no value come through to display. if the booking is deleted, the booking flagged as canceled. Any idea how to add the canceled value to the activity with…