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

React: best way to handle re-render of unrelated components

maybe this is very basic, but I'm still new to react: I want to have different types of components - with (possibly) no relation to each other - that re-render on changing one specific value in my application. I tried the Provider store of mobx,…
0
votes
1 answer

Pass data between controllers which shouldn't depend on each other

I'm facing a design problem in my Java project. I have a MainWindow frame with several panels which control a microscope in our lab. Each of these panels has some text fields, buttons, etc... to execute a specific task . I have designed my program…
dennis-tra
  • 1,309
  • 1
  • 14
  • 23
0
votes
2 answers

How to return the values of a query using the observer pattern

I am new in this Scala world and I would be thankful if someone could help me. So, I am building a Scala application that saves files to a mongodb database using the MongoDB Scala driver. I was using Casbah before, but since it says in the mongodb…
Israel Zinc
  • 2,713
  • 2
  • 18
  • 30
0
votes
2 answers

Is it appropriate to use the Observer Pattern?

Support I have a Java Bean class that strictly holds instance fields: class College { building = "Burruss"; dean = "Mr. Bergess"; schools[] String = {"College of Engineering", "Business School"}; valedictorian = "Mr. Smart…
user402642
0
votes
0 answers

Logical checkboxes in treelist

I've got a treelist with checkboxes. This treelist holds many items of the same type, distributed across several layers. Now if the user unchecks one item, all items of the same type shall be unchecked as well. Can you give me advice how to…
Max T
  • 25
  • 9
0
votes
2 answers

JavaFX Increasing the number failed

In my Example I am trying to make a counter; It starts with 0 and everytime i click the button it must be increase one more. I add a PREFIX and than my increaseNumber() method have to function but it doesn't work. Did I create my EventHandler…
user6941415
0
votes
2 answers

Consuming paginated service in Angular2 & Ionic2 using Observables

I have a remote collection of interface Foo { id: string; properties: any; } Which I can access using a class FooAPIService { find(skip = 0): Promise { // promises at most 5 Foos. to get more, use skip > 1 // pagination is…
bosticko
  • 763
  • 9
  • 21
0
votes
4 answers

Why should we use Observer/Pub-Sub pattern here?

I am trying to learn Observer and publisher-subscriber pattern. came through this simple example here Problem: There is a button and onclick of the button it should be updating the count. without any pattern i can do simply as window.onload =…
0
votes
1 answer

[ios]add observer to Target Application from the Framework or custom static library

I have developed an ios lib/framework where i record user login and connect to the server and fetch data from server real time. In the same library/framework I would like to add observer to my application so that I come to know when the app went in…
0
votes
1 answer

is it possible to put a condition inside an observe_field helper?

using an observe_field helper, i am saving data and making a spinner visible while updating. in addition, i would like to update a div. could it be done with a condition inside the observe_field helper like so? <%= observe_field 'act_feb', :url…
Jay
  • 6,206
  • 11
  • 48
  • 82
0
votes
0 answers

Angular2(RxJS) Subscription don't fire at first click

I would like to observe the event inside of one componenet and then fire diffrent event i another one. I have declare service and such code inside private updateIncomingMaterial = new Subject(); incomingMaterialUpdate$ =…
Stefan
  • 1,431
  • 2
  • 17
  • 33
0
votes
3 answers

rails observe_field

i have used observed_field for arrays of data... but i am having trouble making a simple, one field application of it work. i must be missing a very simple detail. have searched extensively for basic syntax and cannot find anything that applies.…
Jay
  • 6,206
  • 11
  • 48
  • 82
0
votes
4 answers

Java "extending" an object

I have only recently gotten back into Java programming and am currently stuck with a certain problem. I have an object of a certain type: StandardClass stdClass = (StandardClass)request.getAttribute(ATTR); But now I need to make the Object…
0
votes
0 answers

Long running tasks using TPL task scheduler

I am consuming one data streaming source which pushes data in interval >= 5 seconds. I have one observer like below to receive push notifications: public class ConsoleDataObserver : IObserver { private DataPipeType…
Abhay
  • 928
  • 1
  • 10
  • 28
0
votes
1 answer

Observer Design Pattern - Need help to understand why this is not working

Would someone be kind enough to look at this simple program and tell me what's wrong with the implementation of the Observer design pattern? When I run it, nothing shows up in the table (was showing before the implementation). I'm just starting to…
sly-gdk
  • 15
  • 6