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
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
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
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
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.1k
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.1k
3 votes
1 answer
254 views

Store first value of http request with rxjs but keep doing httprequest

With RXJS library : I need to store values from the FIRST http request, but keep doing other http request on demand. I have done this code so far, and that is working. But I think there is a more ...
Stefdelec's user avatar
  • 131
1 vote
0 answers
2k views

Simple chat client and server in Java. (tried to refactor on Head First Java code example)

In the book Head First Java there was this coding example that created a very simple chat client and server. Both the server and the client consisted of just one class. I left the server code as is, ...
Rick's user avatar
  • 195
2 votes
0 answers
454 views

Network of senders and receivers in C++

I am trying to create a Sender-Receiver Network. What do I mean under a Sender-Receiver Network. That means that there is some structure which consists of Nodes and connections between them which will ...
paraxod's user avatar
  • 31
1 vote
2 answers
978 views

Angular2/4 broadcast service using RxJS

I am no expert in RxJS as I am still learning my way around the new paradigm of Observable/Subject. I was trying to implement a broadcast service (based on NgRadio) that allows a new subscriber to ...
Codewarriro's user avatar
1 vote
2 answers
123 views

Lightweight flexible observer framework using weak references

I found a need for a simple, generic publish-subscribe framework for my Java application. I looked over a few implementations on Code Review and I think mine avoids most of the pitfalls. Single-...
ndm13's user avatar
  • 718
3 votes
0 answers
191 views

F# Observable.subscribeWeakly implementation

In this SO question I needed an observable subscription function that can be used kind of like Observable.subscribe, but that does not keep a strong reference to ...
cmeeren's user avatar
  • 185
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
0 votes
1 answer
443 views

Merging union Observables

I am having a scenario where I need to execute observables that depends on the result of the first one. However I need to keep the result of the first observable. I couldn't find any extension that ...
Bruno Costa's user avatar
  • 5,566
3 votes
0 answers
278 views

Simple C++11 Subject-Observer

Building on the answer in C++ class member callback simple examples, I've tried to put together a simple subject-observer pattern without needing to inherit a virtual Observer class. I also wanted to ...
rsjaffe's user avatar
  • 253
1 vote
1 answer
634 views

Observer pattern for temperature and pressure sensors

I have tried to implement the observer pattern. The code should be able to handle a variable number of observables (set compile time) and notify any number of observers/registerables. Any observable ...
TradingDerivatives.eu'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
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
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
0 votes
1 answer
1k views

WPF async ObservableTaskQueue class

I'm currently working on a WPF application, making calls to various web APIs. Thus, I'm looking after a special observable tasks queue: Progress value must be available Tasks (API calls)/seconds must ...
Profet's user avatar
  • 103
2 votes
1 answer
294 views

Removing same event from listener

I have a myDiv.mousedown, window.mousemove, and window.mouseup event. I'm trying to organize ...
Steve's user avatar
  • 121
2 votes
2 answers
223 views

Brightness adjustment control for multiple UI elements

I have an application that basically exists as a map and some controls. The controls change the look and feel of the map. I have a slider which is used to change the brightness, for example. At the ...
Michael's user avatar
  • 778
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
2 votes
1 answer
129 views

Using a new thread to post to observers

I have implemented my own Observer pattern. I want to post my events in a new thread. This thread would simply call all the the observers/listeners with the posted event. ...
J_Strauton's user avatar
3 votes
0 answers
717 views

Rust publish/subscribe channel library

I've written a simple multiple-sender multiple-receiver channel, but I'm unsure if my approach is the best way to do this. I'm not using multi-threaded primitives but instead wrapping around std's ...
creato's user avatar
  • 31
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
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
3 votes
0 answers
1k views

JSON Data Observer

I wrote a small piece of code for observing changes on JSON object. Whenever there is a change in Object, it should trigger all the handlers with simplistic information about data change. I am ...
SoI's user avatar
  • 175
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
0 votes
1 answer
684 views

Long running in-process Publish/Subscribe class

I have a Pub/Sub class that will call Notify() when published and that Notify() could take around 10 seconds, so I need to make ...
Jamie Rees's user avatar
2 votes
2 answers
208 views

Observer pattern implementation in JavaScript

I'm working on redeveloping a running project, and the main goal is to enhance the JS code as much as possible. I'm using the observer pattern to watch the window ...
Muhammad Hamada's user avatar
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
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
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
2 votes
1 answer
856 views

Implementation of observer pattern in web app to monitor an RSS feed

I implemented observer pattern and it will be great if someone can do review of my work and say what should be done better. What is the problem. Application monitoring rss channel, if there is ...
Pulkownik's user avatar
  • 317
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
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
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
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
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
2 votes
1 answer
143 views

Class simulating a connection among two pins

Following this post and the one before that, here I am asking for a review on another piece of code: the connection among two pins. As usual, be merciless in your review. Here it goes: ...
Gentian Kasa's user avatar
  • 2,046
2 votes
2 answers
838 views

Observer pattern implementation

I'm reading Head First Design Patterns and I'm currently reading about the observer pattern. Is what I produced correct? ...
user3392999'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
2 votes
2 answers
2k views

Observable Collection “Deep”

In a project of mine I needed a class "Document" to be able to notify any change in its fields. This class keep a collection of class "AnotherClass". Using an ObservableCollection for this collection ...
SteBert's user avatar
  • 29
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
2 votes
0 answers
118 views

Updating the coordinates of items possessed by a moving person

A Person has coordinates and an Item has coordinates as well, and hence both are derived from ...
prestokeys's user avatar
  • 1,351
0 votes
1 answer
344 views

Does Java need an Observable object with generics?

This is the follow-up question from here. This is an Observable class similar to java.util.Observable. The difference is that ...
hkoosha's user avatar
  • 153
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
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
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
2 votes
3 answers
2k views

ObservableQueue

I'm looking for feedback on this. ...
ChaosPandion's user avatar
  • 1,753