Questions tagged [observer-pattern]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
210 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
115 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
  • 25
0 votes
1 answer
786 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
291 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
481 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
1k 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
1 vote
1 answer
592 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
1k 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
465 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
99 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
713 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
313 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
406 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
253 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
476 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
  • 403
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
192 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
  • 305
1 vote
1 answer
333 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
169 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
  • 356
5 votes
4 answers
2k 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
22k 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
645 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
653 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
184 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
255 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,245
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
81 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
231 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
135 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,729
2 votes
1 answer
783 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
687 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,093
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
692 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
16 votes
1 answer
12k 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
763 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
2 votes
2 answers
2k 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-...
Cristian's user avatar
  • 125
1 vote
3 answers
560 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 ...
nickbw's user avatar
  • 252