Questions tagged [observer-pattern]

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.

Filter by
Sorted by
Tagged with
14 votes
1 answer
13k views

The Observer design pattern in Python, with unit tests

I'm continuing to work on the Head First Design Patterns book in an effort to become a more efficient and better Python programmer. Code review for the Strategy pattern in Chapter 1 is here with ...
PythonJin's user avatar
  • 485
12 votes
1 answer
613 views

Observable Object

I have created an observer and an observable object class. The idea being that you can create an observer that does some action whenever object being observed changes value. Design goals: Be able to ...
schrödinbug's user avatar
11 votes
1 answer
25k views

Angular 2 clock with RxJS Observable

I'm fairly new to Angular 2 and I started off with creating a clock for my app. I tried to stick to the official documentation tutorial. Folder structure: The CSS file is still empty and the HTML is ...
OddDev's user avatar
  • 411
10 votes
2 answers
2k views

Retry and CircutBreaker the reactive way

I wrote a simple utility for Retry and CircuitBreaker patterns. I implemented it by using ReactiveX because I thought it might actually be the perfect framework for it. I know that there is a project ...
t3chb0t's user avatar
  • 44.2k
9 votes
2 answers
1k views

Observable Object Proxy

As a part of my (future) MVVM framework, I need to be able to detect changes on an object. To do this, I used the RealProxy, a C# object that implements Aspect ...
IEatBagels's user avatar
  • 12.4k
8 votes
3 answers
14k views

Listening to modifications on variables

I am seeking advice on the efficiency and long term implications of various ways of capturing modifications to instance variables that I have tried implementing. Essentially, this is setup: In my ...
psychicmachinist's user avatar
8 votes
1 answer
2k views

Observer pattern implementation in C++11

Can this observer pattern implementation be improved? Problem: User will drive a car if pressed l --> car move left c--> move middle ,r--> move right ...
rim's user avatar
  • 227
8 votes
1 answer
245 views

WindMIll Data Publisher using observer pattern

Problem statement : There is a windmill which collects and stores wind data for various cities. The data is maintained in an xml file by the aggregator part of windmill. Now I am trying to implement ...
Hummingbird's user avatar
7 votes
1 answer
3k views

Message bus in C#

I wrote a MessageBus class whose only purpose is to deliver messages from object to object without direct link between them. I encountered a problem with duplicate ...
Bohdan Yarema's user avatar
7 votes
1 answer
395 views

Threadsafe oneshot-event which fires on subscription if the event was fired in the past

Assumptions Basically, a Connection class has a "Disconnect" event. Subscribing to this event isn't thread-safe, because the disconnection may fire from another thread right before I subscribe. So ...
Oachkatzl's user avatar
  • 173
7 votes
1 answer
190 views

JS stopwatch using the observer pattern

I'm learning OOP and also trying to learn and implement some design patterns. This question is a follow-up of Stopwatch interface OOP (Vanilla JS) The app is available in https://nacho-p5.github.io/ ...
nabla-f's user avatar
  • 163
7 votes
0 answers
246 views

Scheduler built with observables v2 (follow-up)

It would probably be too easy if the old Scheduler worked as intended being that simple. But an eye-openig review showed that from time to time it'll miss one ...
t3chb0t's user avatar
  • 44.2k
6 votes
1 answer
3k views

Observer Pattern with an Observer observing multiple Subjects

Is the below a good solution for an observer to monitor multiple subjects. My only fear is that if an observer was monitoring a wide range of subjects then the update method could get quite large ...
Peter Featherstone's user avatar
6 votes
1 answer
2k views

Observable template in modern C++

I'm trying to create a modern template class for a generic observable: ...
Matias Suarez's user avatar
6 votes
1 answer
4k views

Java Pub Sub implementation using broker

I have developed a simple pubsub event subscription in java. Something similar to this thread Simple Pub-Sub Event Emitter These are the goals. Class should be able to "listen" to events happening ...
Grrrrr's user avatar
  • 297
5 votes
2 answers
2k views

Logic gates simulation

Following this post and this other post here we are with another review request. The code that follows contains the definition of logic gates (binary gates like the AND, OR gate, and unary gates like ...
Gentian Kasa's user avatar
  • 2,046
5 votes
1 answer
4k views

Implementation of Observer Pattern in C++14

I have written a small class for implementing the observer pattern in C++(14). I would welcome any comments, corrections criticisms and suggestions. Observable.h: ...
bone's user avatar
  • 191
5 votes
2 answers
2k views

C++ implementation of the observer design pattern

Started learning design patterns using C++. Below is an implementation of the Observer Pattern. Two abstract class templates Observer and ...
user avatar
5 votes
1 answer
140 views

Scheduling using System.IObservable 2.0

As a follow up to this first attempt to create and use my own IObservable<T> implementation, this is version 2.0. The goal has been to correct the code where ...
user avatar
5 votes
2 answers
159 views

TextBoxes for various number types

Is there a way I could somehow have all this classes condensed into one, while keeping the code as clean as possible? They are all doing essentially the same thing, just for the different number type....
Karlovsky120's user avatar
5 votes
2 answers
1k views

Scheduler built with observables

I sometimes have to schedule some tasks and wanted to have my own reusable scheduler. Since I like the Rx, I build it on top of it. Follow-up There is a newer version of the ...
t3chb0t's user avatar
  • 44.2k
5 votes
1 answer
87 views

News reading application version 2

following the answer I got from t3chb0t last time News-reading application using the Observer pattern and also following the example here https://msdn.microsoft.com/en-us/library/dd990377(v=vs.110)....
Gilad's user avatar
  • 5,321
5 votes
1 answer
3k views

Simple event manager in Java

I have created a simple event manager and I want it to work properly in a multithreaded environment: ...
dyesdyes's user avatar
  • 171
4 votes
2 answers
179 views

Dependency problem with field changes

The Observer Pattern is used here to notify changes in a Person's data. For example, when age changes, the value of can_vote() ...
prestokeys's user avatar
  • 1,351
4 votes
2 answers
7k views

java.util.Observable but with generics to avoid casts

This is an Observable class similar to java.util.Observable. The difference is that it uses generics to avoid casts. The ...
hkoosha's user avatar
  • 153
4 votes
2 answers
4k views

Observer pattern using a set of observers and delegated properties

The idea is to implement the observer pattern, with a separate notification method for each observed property of the observed object. Let me start with a simplified use case: ...
Thomas's user avatar
  • 208
4 votes
3 answers
296 views

Observer Design Pattern in C++ to model magazine subscriptions

My attempt at a observer design pattern (I know using namespace std isn't good). I'm very new to design patterns. Everything is inline with class definition. Please tell me if I'm doing anything wrong ...
Asphodel's user avatar
4 votes
1 answer
4k views

Simple event dispatcher

Here is my very first event dispatcher. I would like to get both, style and code review, as well as some ideas to improve this implementation (new features etc.) I tried to write code in C++17 style ...
NutCracker's user avatar
4 votes
2 answers
1k views

Make an Array Reactive (Observable)

I have written a simple JavaScript function to make an array reactive (i.e. observable). Is there anything I could improve? What the code does is take an array, a callback and a ...
Jacques Marais's user avatar
4 votes
1 answer
2k views

Checkbox binding to change the ListView's items source

I am using a checkbox to filter some components on my ListView by changing the variable's content which is bound to this ListView...
Mehrad's user avatar
  • 812
4 votes
2 answers
3k views

Angular - reusing an observable for different queries

This is just a dummy example, but in my real world application I get a lot of data from the web API and I'd like to manipulate it on the client's side. So, I kind of stored the observable I get from ...
uglycode's user avatar
  • 141
4 votes
1 answer
4k views

2D board game: good Model part?

First time writing a big project in OOP. I am quite used to scientific programming but not to OOP, and even less to building GUIs. I am writing a 2D board game: the player can move on a map from tile ...
presenter's user avatar
  • 193
4 votes
1 answer
1k views

Observable Logger

I'm experimenting with an alternative abstraction layer for logging that is build on top of the Reactive Extensions. This allows me to easily add features I need to my layer and map logs to any other ...
t3chb0t's user avatar
  • 44.2k
4 votes
3 answers
5k views

Custom Implementation of ObservableDictionary

I recently found myself in need of an IDictionary<TKey,TValue> implementation that was observable from a WPF UI. Since the .Net framework does not provide ...
psubsee2003's user avatar
4 votes
1 answer
159 views

Scheduling using System.IObservable

With great inspiration from t3chb0ts ongoing work about scheduling, cron jobs etc. (last post here), I decided to make my own version of the Scheduler - using the observer pattern - as a learning ...
user avatar
4 votes
1 answer
2k views

Implementation of Observable with multiple callback function signatures

I have been playing around with ways of implementing a generic class for supporting the observer pattern. I have already asked to review a basic approach here. Now I have come up with an Observable ...
bone's user avatar
  • 191
4 votes
1 answer
2k views

Observer Pattern with C# and Unity

I want to see if I used the Observer pattern correctly. Right now I'm using a VolumeManager.cs that implements ISubject and a <...
Funlamb's user avatar
  • 619
4 votes
1 answer
2k views

RxJS Subscription Service in Webworker

Here is a plunker of my working demo. I have the following code which I have created for a subscription service for data through a webworker. I was wondering if I was following functional-reactive ...
John's user avatar
  • 384
4 votes
0 answers
118 views

Scheduler built with observables v3 (follow-up) - now testable

This is a 2nd follow-up to my previous one about a Scheduler built with observables. Although the last one was working correctly, it was only possible to see this ...
t3chb0t's user avatar
  • 44.2k
3 votes
3 answers
946 views

Observer pattern implementation in C#

In order to implement the Observer pattern in C#, one of the ways to go (at least, the one I chose) is to make classes that implement the IObservable<T> for ...
Gentian Kasa's user avatar
  • 2,046
3 votes
2 answers
522 views

Generic Observer/Listener implementation in Java

I am working on a personal project in university where I am currently trying to make my own implementation of a generic observer pattern that I can use throughout my project. I would appreciate any ...
Emil Holmsten's user avatar
3 votes
1 answer
328 views

Implementing the observer pattern for a stock exchange scenario

I am trying to implement the observer pattern for a stock exchange scenario. Multiple stocks can be registered at a stock exchange. There will be stock observers who are observing some specific stocks....
Mahesh Jagtap's user avatar
3 votes
1 answer
2k views

Angular service for fetching and passing data with observables

I have an Angular service consisting of three methods: This method makes a call to my server to get a URL ...
Noah Hornak's user avatar
3 votes
2 answers
599 views

Custom event handler in Javascript

In my web projects I often need a simple way to trigger callbacks defined somewhere else. Leaving jQuery finally behind me, I was missing their simple event system and tried to create my own. I'd like ...
Moritz Friedrich's user avatar
3 votes
2 answers
892 views

A Python decorator for an "observable property", that notifies observers when the data is changed

I have classes that have some data, and whenever this data changes, it should notify observers of that data change. There also should be a method to add new observers. My first approach was to use a ...
Blue7's user avatar
  • 373
3 votes
2 answers
834 views

Reusable Implementation of the Publish-Subscribe Pattern

I've finished an implementation of what I believe the Publish-Subscribe pattern is for practice and possible use in personal projects even though this implementation is fairly similar to the Observer/...
Valkryst's user avatar
  • 133
3 votes
1 answer
111 views

Abstract wrapper for fundamental types

I have created this interface as part of my C++ learning path. This post inspired me a lot. The idea is to use its concrete implementations to perform some actions before and after any change of the ...
EmaPrn's user avatar
  • 31
3 votes
1 answer
75 views

High-Level Managed Observers

I was thinking of adding a very high-level implementation of the event/observer pattern to my project. The implementation would manage adding and removing observers as "needed". You can use an almost ...
Nic.Star's user avatar
3 votes
1 answer
103 views

Logic is stored in Components that receive input data and update output data via Observables

I have C# ASP.Net Core Webapi application that makes some calculations for physical models. I have this project class: ...
rst's user avatar
  • 207
3 votes
1 answer
402 views

Observer design pattern in Swift

The problem: We have a set of mobile mechanics who are assigned specific zip codes. Each zip code has its own hourly rate. We want to increase and decrease these rates when the number of idle ...
Reza Shirazian's user avatar