Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [observer-pattern]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
4 answers
140 views

What is the advantage/disadvantage of returning a UnSubscribe class to Observer as opposed to just calling a UnSubscribe method of Observable?

There are two ways to provide a way unsubscribe in Observer Design Pattern. 1. Provide a simple void UnSubscribe method: public void UnSubscribe(IObserver observer){ // remove observer from List of ...
SamuraiJack's user avatar
0 votes
2 answers
131 views

Push and Pull Communication in object oriented: why Push style is not flexible?

I'm trying to learn Observer Design Pattern and I started to watch the series which belongs to codewithmosh called "The Ultimate Design Pattern Series". in the lesson which was about ...
Mehdi's user avatar
  • 29
0 votes
1 answer
353 views

Observer pattern using static events

I'm working on a game prototype: I have a Cell class which, given a mouse click on its collider, can raise an event that should be listened in two different modules: Camera and UI. The Observer ...
vandermies's user avatar
6 votes
3 answers
2k views

Connotation difference between "subscribers" and "observers"

In the observer pattern, and similar, is there a meaningful difference between "subscribers" and "observers" in the wild, or in the lit? With RxJS and (functional) reactive ...
Alexander Mills's user avatar
-1 votes
2 answers
139 views

How to make domain objects accessible to MVC controllers and views?

Summary of my question in a short form: How to propagate changes of domain objects upwards without introducing application logic into them? Following 'facts' are based on prescriptions from respected ...
reign's user avatar
  • 125
0 votes
1 answer
1k views

is there a two-way (bidirectional) observer pattern?

I have two classes. "System" and "Bluetooth". I want to have a really loose coherency between these two classes as they should be able to exist or not without depending on each ...
Mahyar Shokraeian's user avatar
0 votes
1 answer
448 views

Clean code: Register listeners inside class handling events, or outside?

I'm writing a Java program with a custom event manager, which is of course the observer pattern. Should the calls to add event listeners/handlers be in the classes that listens/handles the events ...
user1902689's user avatar
3 votes
3 answers
769 views

Class A uses class B. Class C contains an instance of A (composition). Should the diagram reflect the fact that C is dependent on A?

I made a simple 2-window UI to practice the Observer pattern (which I hopefully managed to implement correctly): a window with some text fields meant for adding a new book to a list another one ...
sashilio's user avatar
0 votes
2 answers
2k views

Who is the Observer in MVC? Controller or Views?

Implementing the Observer pattern in MVC could mean making Model Observable and View Observers. However, this also means that there will be direct communication between views and models without the ...
a_fan's user avatar
  • 145
3 votes
1 answer
755 views

C++: Broadcast/observer pattern with polymorphic events

I'm currently trying to implement an event-system following a broadcast/observer scheme. I have events/notifications that contain information about what is happening: class Event { public: Event(...
TheBeautifulOrc's user avatar
1 vote
2 answers
2k views

Is a python `abstract property` that returns an abstract class an example of the Factory Pattern?

I need to document my design, in particular, the design patterns used, and would like to use the standard terminology. From Refactoring Guru, "Factory Method defines a method, which should be ...
Blue7's user avatar
  • 137
4 votes
1 answer
536 views

Listener pattern vs Whiteboard pattern

I'm trying to understand the motivation of these two patterns. I think the listener pattern is just a pub-sub, and the use case is mainly in a distributed manner, for example, the AWS SNS is just a ...
ChuNan's user avatar
  • 167
0 votes
1 answer
103 views

Does every use of events count as implementing the Observer Pattern?

Lets say I have the following code in my GamePanel class: public GamePanel(Menu menu){ this.addMouseListener(new PlanterListener(this)) PlanterListener class: public PlanterListener(GamePanel game){ ...
Felix Jönsson's user avatar
5 votes
3 answers
772 views

How to avoid DI dependency cycle for observer pattern

In my project I'm using the observer pattern in several places, i.e. the subject notifies the observers about something, and expect them to act. The subject does not know anything about the details of ...
C-Otto's user avatar
  • 169
1 vote
0 answers
340 views

Common patterns for Observable data layer on iOS

I am working on learning native iOS development in Swift, and I am trying to find something that is similar to what I've learned in Android development with Kotlin. In particular I am referring to ...
papafe's user avatar
  • 171
3 votes
1 answer
433 views

I often create class cycles by using the Observer Pattern. How can I avoid this?

I often find myself creating class cycles by using the observer pattern. Consider the following scenario: I have a central accessible global data source (Subject) The data source is reflected by many ...
Konstantin Hatvan's user avatar
0 votes
2 answers
1k views

Model View Controller pattern for a Java desktop application

I'm struggling to fully understand MVC pattern, I found a lot of information on the web but they are really confusing because it seems there are various ways to do it. What I understood is that the ...
Diablo3000's user avatar
2 votes
3 answers
302 views

Java Observable API - when is it a "pull" scenario?

I am reading about the Observable pattern (Head First Design Patterns) and it is not very clear why it is saying that "You can push or pull data from the Observable when using the pattern". I ...
Victor's user avatar
  • 133
1 vote
2 answers
570 views

Is using an enum to differentiate different events in an observer pattern plausible if it's on a small scale?

I need to collect statistics during an algorithm. To not mix the statistical code with the algorithm code too much, I'd like to decouple that by publishing "statistical events" that can then be ...
Joe's user avatar
  • 405
16 votes
3 answers
6k views

Is using Observer pattern a good idea while building a Chess Game?

I am trying to design a Chess Game using OOPs concepts that has a UI element to it. My idea is to show the number of squares / cells a piece can travel to when selected. Basically I want to show the ...
Auro's user avatar
  • 291
2 votes
3 answers
204 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(); ...
Mateo de Mayo's user avatar
4 votes
2 answers
1k 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 ...
lahory's user avatar
  • 315
1 vote
1 answer
402 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 ...
Sook Lim's user avatar
  • 167
3 votes
2 answers
172 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 ...
Water's user avatar
  • 366
5 votes
4 answers
3k 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. ...
ha9u63a7's user avatar
  • 397
10 votes
3 answers
24k views

What's the difference between Observer pattern and listeners?

I have used some kind of "listeners" where I have an interface implemented by classes that need to be notified of some event (e.g.: CurrencyListener, with a method currencyUpdated(Currency ...
user315772's user avatar
6 votes
2 answers
3k 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 ...
Shenron's user avatar
  • 71
3 votes
1 answer
658 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 ...
Ricardo Faria's user avatar
3 votes
5 answers
2k 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....
Ben Schwabe's user avatar
0 votes
0 answers
661 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 ...
Ruudjah's user avatar
  • 558
6 votes
3 answers
3k 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 ...
tir38's user avatar
  • 203
3 votes
1 answer
1k 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 ...
Jef Patat's user avatar
  • 223
1 vote
1 answer
185 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 -...
kayleeFrye_onDeck's user avatar
3 votes
1 answer
1k 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 ...
PythonNewb's user avatar
3 votes
1 answer
263 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; ...
overexchange's user avatar
  • 2,265
3 votes
1 answer
1k 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(...
user2585494's user avatar
0 votes
1 answer
84 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(...
Little Alien's user avatar
3 votes
4 answers
243 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 ...
virtualnobi's user avatar
0 votes
1 answer
145 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 ...
Alexander Bird's user avatar
5 votes
1 answer
3k 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 ...
gardenhead's user avatar
  • 4,747
2 votes
1 answer
833 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 ...
Sh4d0wsPlyr's user avatar
10 votes
2 answers
3k 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 ...
user1803551's user avatar
0 votes
2 answers
717 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 ...
Vorac's user avatar
  • 7,119
7 votes
4 answers
1k 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 ...
nonopolarity's user avatar
  • 1,827
1 vote
1 answer
715 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: ...
user3998276's user avatar
3 votes
1 answer
4k 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 ...
mwloda's user avatar
  • 141
17 votes
1 answer
13k 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 ...
user183536's user avatar
4 votes
1 answer
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 ...
Dang Khoa's user avatar
  • 203
1 vote
3 answers
764 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 ...
CAMD_3441's user avatar
  • 209
1 vote
2 answers
1k 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 ...
abl's user avatar
  • 471