The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [observer-pattern]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
3answers
124 views

Is the observable pattern the right tool for this scenario?

Suppose I have a Player that wants to build a Tower in the Board of a tabletop game. My first approach to this would have been something like: function onConfirm() { player.consumeResources(); ...
2
votes
2answers
335 views

Is observer pattern abandoned by the industry now (2019)? [closed]

While working on a refactoring task of a legacy app, I came across a scenario where a series of cause->effect type events are happening and currently everything is being handled inline. To give you ...
3
votes
5answers
635 views

Using Observer Pattern to selectively act on events

I'm currently in the process of architecting a small RPG-style dungeon crawl (in Unity), and am a little stuck on how to update various objects when things change, while not updating unrelated objects....
1
vote
1answer
63 views

Is the sequence diagram for the pull model for observer pattern the same as push model?

I've been looking at examples of sequence diagrams for observer pattern but most implement push model where the subject updates the observers. In a pull model how would it be different because ...
3
votes
2answers
148 views

Preventive measures for stopping developers from forgetting to update cached values

I'm at the point where results need to be cached to make the application more responsive. From experience in a previous project, countless (to say the least) bugs occurred because there was lots of ...
5
votes
3answers
423 views

Observer Pattern and Circular References

I was checking this example of Observer Pattern. https://www.tutorialspoint.com/design_pattern/observer_pattern.htm It seems that there is a circular reference when Observer Pattern is used. ...
3
votes
1answer
3k views

Observer for two independent events in the observable class

Observer pattern aim: the observer class responds to the changes of the observable class state. Problem. There are different processes inside observable class that should be observed. Those events ...
2
votes
2answers
2k views

Any OOP design pattern that is somewhat representative of all of the SOLID OOP design principles at play?

I'm trying to teach an object oriented design principles course (on SOLID) at a training institute. I also want to teach the students a few OOP design patterns such as factory, singleton and one other....
6
votes
2answers
2k views

API Design - Observable vs Callback

We as a team are writing an C# SDK which communicates with a Server endpoint. All our API's till now have been Task based. Like Task DoOperationAsync() Recently we across a need for API which gets ...
1
vote
1answer
168 views

What's a good robust way to query processes for their help or framework origin especially in Windows?

What's a good robust way to query processes for their help or framework origin, especially in Windows? I've got an automated testing module that queries binaries that fit a special name pattern with -...
4
votes
1answer
2k views

In MVC, who is in charge of handling observers?

(I'm writing a large MATLAB GUI that makes significant use of MVC, so my example is written in MATLAB. However, I believe this question is language-agnostic. Please correct me if I'm wrong.) I have a ...
3
votes
1answer
486 views

Is Content Observer an implementation of Observer Pattern?

Observer Pattern is defined by the 'Gang of Four' Design Patterns book as a "one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated ...
0
votes
0answers
408 views

What is the cleanest way to model my domain in JavaScript?

I am building an SPA. It will use WebGL, Canvas and SVG for certain components, and html for rendering views. I have a messaging system setup to define messages coming from a server, which will get ...
6
votes
3answers
2k views

When building an observer pattern (event pattern) is it better to use classes or an enum for events?

When building an Observer pattern, you need to define your events that the are broadcast and observed. Is it better to define an abstract Event class with multiple subclasses for each event, or to ...
2
votes
1answer
545 views

Connect observers to observable automatically using dependency injection container

I have several services that implement an observer interface and one service that implements the corresponding observable interface. I'm currently using unity together with Prism so I would prefer to ...
3
votes
4answers
211 views

Using ObserverPattern, but need to stop some observers displaying changes immediately

In a GUI application (to organize images), I use the Observer Pattern (or anything similar to model-view-(view)controller) to inform other components about changes. Assuming three components A, B, C ...
9
votes
2answers
2k views

Is the observer pattern suitable when the observers are not independent of each other?

I have a class Car which has 2 properties: int price and boolean inStock. It also holds a List of abstract class State (empty class). There are 2 states which can be applied on the car and each is ...
2
votes
1answer
732 views

Implementation of observer pattern with one observer/multiple publishers and multiple events?

I'm in a bit of a tricky situation where I need to use the Observer pattern but I don't really know the best way to go about it. Here's a quick briefing on my application: I'm implementing a GUI ...
3
votes
1answer
178 views

State propagation(bottom-up) in multi-walk tree

Using the Tree representation(mentioned below), typedef enum {Running, Warning, Critical}Status; struct TreeNode; typedef struct List{ int childCount; struct treeNode **childList; }List; ...
3
votes
1answer
956 views

Observer pattern for rest services with UI client

I am developing restful services using resteasy for an application. This application has UI which will consume these rest services. Now I am having a case where I have to do a server push to UI(...
0
votes
1answer
77 views

Mutual observer

I want my Wire objects to be in connection with Port objects. That is Port has a list of connected wires and method Port.add(wire). Similarly, Wire has list of ports it is connected to and Wire.add(...
10
votes
3answers
7k views

Observer pattern; knowing *what* changed?

I've created two abstract classes Subject and Observer that define a classic Observer pattern interface. I derive from them to implement the Observer pattern. An observer might look like this: void ...
0
votes
1answer
86 views

Can I call DOM event handling an instance of observable/observer pattern

In the following DOM event handling example (using jQuery): $('#shopping-cart').on('click', function(event){...}); could I not call the shopping-cart DOM element the observable, and the function the ...
0
votes
2answers
400 views

Is this example implementation of the Observer pattern well-written?

It seems as if this example implementation of the Observer pattern is drawn from the book Headfirst Design Patterns, OReilly, which I am currently reading. Here is a UML diagram from the book It's ...
2
votes
1answer
2k views

What are the advantages of Observables over an iterable of futures?

I recently came across the ReactiveX pattern for asynchronous data-flows. I studied the information provided there and also watched this talk by a Netflix engineer on how they used Observables to ...
2
votes
1answer
557 views

Observer Design Pattern with complicated objects

I am trying to currently get a good grasp on the Observer design pattern, but I am stuck wondering about one specific issue. In the examples I have been able to find of implementation, they are all ...
3
votes
3answers
356 views

Optimal communication pattern to update subscribers

What is the optimal way to update the subscriber's local model on changes C on a central model M? ( M + C -> M_c) The update can be done by the following methods: Publish the updated model M_c to ...
9
votes
4answers
5k views

Was .NET's IObserver<T> intended for subscribing to multiple IObservables?

There are IObservable and IObserver interfaces in .NET (also here and here). Interestingly, the concrete implementation of the IObserver does not hold a direct reference to the IObservable. It doesn'...
6
votes
4answers
695 views

Is it true that for Observer Pattern to work, there probably is some polling mechanism underneath?

The short question is: is it true that for Observer Pattern to work, there probably is some polling mechanism underneath? (update: in a network situation) It was quite amazing that if on my Macbook ...
9
votes
2answers
3k views

Observer pattern over HTTP and TCP/IP (Server-Client)

I have a server and many clients (around 50 clients) who connect to that server based on a web application, which is of course based on HTTP protocol, which in turn uses TCP/IP (correct me if I'm ...
1
vote
1answer
411 views

Should listener interfaces be nested?

In Java the observer pattern is implemented with at least one interface (often ending in Listener or Observer). Such interfaces can be placed nested inside the class or be separate, for example: ...
4
votes
1answer
353 views

Would this be an effective use of the Subject/Observer pattern, or is there a better way?

TBH: I've never used an observer pattern. But it looks pretty useful for this situation: I'm developing a very simple strategy game. It involves two combatants who simultaneously bludgeon each ...
2
votes
2answers
975 views

observer class as instance

Sometimes I read in observer-pattern descriptions, to make the constructor of a observer base class protected so the class will be abstract. but by making the constructor public (if even one is ...
15
votes
1answer
10k views

Difference between Consumer/Producer and Observer/Observable

I am working on the design of an application that consists of three parts: a single thread that watches for certain events happening (file creation, external requests etc.) N worker threads that ...
1
vote
3answers
606 views

C# Subject Observer Architecture question

I'm making a C# application using the Subject Observer design pattern in a slightly different way. I am passing the Provider Class, implementing IObservable (this has the OnNext() method that ...
1
vote
2answers
905 views

Observer pattern without state change?

My question is whether there is a similar pattern to Observer that does not imply a state change in the observed object. The following is a concrete example: I have a ConnectionFactory class which is ...
1
vote
2answers
1k views

Observer pattern: Prevent multiple firings on changed internal property

I have an object Foo that has 2 public properties: A and B. These properties can be changed from outside, as the application I'm working on is using a data-binding architecture. This is the front-...
1
vote
1answer
258 views

Software to access GSM Terminal, sending and receiving AT commands, validating results

I am currently implementing a software that uses a GSM terminal to perform actions. Actions can be sending messages, checking balance, receiving status report messages, setting the pin, ... The ...
3
votes
4answers
204 views

Two user inputs that alter each other

I have a user interface with two numeric input boxes, send amount and receive amount. The values are in different currencies and are related by an exchange rate. That is, receive amount should always ...
1
vote
3answers
476 views

Potential abuse of observer pattern

I have a MeetingRoom object that contains a list of Employees, there is a function on each employee called SetMeetingDate, this method has to take into account the state of all other employees in the ...
2
votes
1answer
617 views

Does key-value observing between model and view violate MVC?

In MVC the Controller is the go-between for the View and the Model. So the Controller should be the one that observes or receives changes from the Model and View and updates the other accordingly. I ...
5
votes
4answers
2k views

Design Patterns for Coordinating Change Event Listeners

I've been working with the Observer pattern in JavaScript using various popular libraries for a number of years (YUI & jQuery). It's often that I need to observe a set of property value changes (e....
2
votes
2answers
984 views

What preconditions should be checked while adding/removing a listener?

Imagine the following interface: interface Service { addListener(Listener l) removeListener(Listener l) } Should I check for null values while add/remove? Is it a good idea on remove to ...
10
votes
4answers
24k views

Which design pattern is more suitable for logging?

I should log some events in a program but as far as I know it would be better to keep the logging code outside the program because it is not about the real functionality of the program. So may you ...
0
votes
3answers
1k views

Are EventHandler<T> and IObservable<T> interchangable?

I have an object which will periodically raise an event based on an action performed in an application. This will be heard by any listener(s) and acted upon accordingly. I do not wish to use a ...
8
votes
1answer
9k views

The Observer pattern using the pulling mechanism

I was wondering about the following implementation of public void update(Observable obs, Object arg) while i want to send to all of my observer and update using notifyObserver() i and passing a ...
4
votes
1answer
969 views

I'm always reimplementing observer/subject code in Java. Is there a better option?

I'm always writing observer/subject interfaces in a particular Java project, e.g.: /** * Registers the receiver to the dispatcher. * When data arrives that the receiver can process, * it will be ...
1
vote
1answer
174 views

Freeing Memory: Observer Pattern?

I am building a scientific application in matlab which handles several hundred large matrices (large as in 'very few of these will fit into ram'). Each matrix is contained within a dedicated object to ...
3
votes
2answers
927 views

UML class diagram: how to annotate observer-subject relationship?

How can I annotate in a UML class diagram that an instance of ClassA is registered as an observer of an instance of ClassB? (Both implement the appropriate interfaces). This doesn't really belong in ...
3
votes
0answers
523 views

Observing multiple observables at once / Network of chained observers

Quick example: HM observes CM SM observes CM HSM observes HM and SM, but wants to be updated only after both have their new value derived from CM. More detail: (this is still a made-up example, but ...