observer-pattern

Clojure Model-View-Controller (MVC) design

南笙酒味 提交于 2019-12-03 12:23:35
问题 I am writing a Desktop GUI application in Clojure using Java Swing. Normally when working with Java I will design the application according to a MVC design pattern using the Observer pattern as well. This way the view is decoupled from the model and changes in either do not affect each other, making changes easier further along. I was wondering if Clojure has a better approach to this problem than normal MVC and Observer design pattern? I'm new to functional programming so i'm not sure how I

can an observer observe multiple observables?

北慕城南 提交于 2019-12-03 08:46:42
trying to find an example of this, it's possible that I am not going the right way around it, or that my mind has over simplified the concept of the observer pattern. I want to create a class that controls messages from a web service, and I want this class to monitor the changes of many other operations. The observer pattern examples I have seen demonstrate many observers watching a single observable, can I (or should I) do this the other way round? What else should I be doing? Just register a single Observer instance in many Oservable instances. You probably will want to pass Observable

Multithreaded Observer Pattern [closed]

烂漫一生 提交于 2019-12-03 08:44:17
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . I have a question where a subject is updated in a different thread every time. So whenever the subject is updated it correspondingly updates the observer with the new information. However, if the list of observers is long, it will require some time to update all the observers. Think

Observer Pattern in Swift

谁都会走 提交于 2019-12-03 08:39:19
I want to implement an observer pattern, but I do not find the proper programming language constructs in Swift (also 2.0). The main problems are: protocol and extension does not allow stored properties. In classes we could add stored properties, but we can not force a subclass to override some of its inherited methods. This is what I want: {class|protocol|extension|whathaveyou} Sensor { var observers = Array<Any>() // This is not possible in protocol and extensions // The following is does not work in classes func switchOn() func switchOff() var isRunning : Bool { get } } class LightSensor :

Observer pattern in Go language

本小妞迷上赌 提交于 2019-12-03 07:12:22
问题 This problem is pretty common: an object should notify all its subscribers when some event occurs. In C++ we may use boost::signals or something else. But how to do this in Go language? It would be nice to see some working code example where a couple of objects are subscribed to a publisher and process notifications. Thanks 回答1: This is actually pretty simple in Go. Use channels. This is the kind of thing they're made for. type Publish struct { listeners []chan *Msg } type Subscriber struct {

Good way to have a Collection Listener?

*爱你&永不变心* 提交于 2019-12-03 05:50:28
Is there a better way to have a listener on a java collection than wrap it in a class implementing the observer pattern ? You should check out Glazed Lists It contains observable List classes, which fire events whenever elements are added, removed, replaced, etc les2 You can using the ForwardingSet , ForwardingList , etc., from Guava to decorate a particular instance with the desired behavior. Here's my own implementation that just uses plain JDK APIs: // create an abstract class that implements this interface with blank implementations // that way, annonymous subclasses can observe only the

How is the Observer pattern different from an Event driven model?

拈花ヽ惹草 提交于 2019-12-03 05:06:21
问题 I am a senior level developer but I haven't had a lot of formal training and I although I have used many design patterns and seen them used in my years as a developer, no one really went out of their way to say. "Oh this is an observer pattern, or this is a Singleton pattern." Reading over some of the design patterns, I came across the Observer pattern and it seems to be to be very similar to the way the .NET framework events work. Am I missing something fundamental about this? 回答1: The .NET

How to create custom Listeners in java?

一笑奈何 提交于 2019-12-03 04:50:05
问题 I want to know about how to set our own Listeners in java.For example I have a function that increments number from 1 to 100. i want to set a listener when the value reaches 50. How can i do that? Pls suggest me any tutorial. 回答1: Have a look at the source of any class that uses listeners. In fact it's quite easy: create an interface for your listener, e.g. MyListener maintain a list of MyListener upon each event that the listeners should listen to, iterate over the list and call the

MediatorLiveData or switchMap transformation with multiple parameters

爱⌒轻易说出口 提交于 2019-12-03 04:18:45
问题 I am using Transformations.switchMap in my ViewModel so my LiveData collection, observed in my fragment, reacts on changes of code parameter. This works perfectly : public class MyViewModel extends AndroidViewModel { private final LiveData<DayPrices> dayPrices; private final MutableLiveData<String> code = new MutableLiveData<>(); // private final MutableLiveData<Integer> nbDays = new MutableLiveData<>(); private final DBManager dbManager; public MyViewModel(Application application) { super

What is difference between observer pattern and reactive programming?

孤街浪徒 提交于 2019-12-03 04:04:40
问题 Recently I heard a lot the term reactive programming . But when I searched for it, what I discovered was only some similarities with observer pattern . Actually, I cannot find any different between them. What's conceptual difference between them and why the term reactive programming is getting buzzed? 回答1: Reactive programming is the general paradigm behind easily propagating changes in a data stream through the execution of a program. It's not a specific pattern or entity per-se, it's an