observer-pattern

Alternative to Java's Observable class? [closed]

◇◆丶佛笑我妖孽 提交于 2019-12-03 03:49:20
问题 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 3 years ago . I'm coming to Java from the C# world where the Observer pattern is implemented as a first-class language construct with the event keyword. I see that Java's had the Observable class since the early days, but it clearly has implementation issues and doesn't seem to be widely used.

C# delegate v.s. EventHandler

情到浓时终转凉″ 提交于 2019-12-03 03:12:01
问题 I want to send an alert message to any subscribers when a trap occurred. The code I created works fine using a delegate method myDelegate del . My questions are: I want to know whether it's better to use EventHandler instead of a delegate? I'm not sure what the differences are between a delegate and an EventHandler in my case. notify(trapinfo t) , that's what I've done here to get trap information. But it seems not to be a good idea. I read some online tutorial lesson introducing passing

Clojure Model-View-Controller (MVC) design

感情迁移 提交于 2019-12-03 02:51:56
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 make the model separate from the view. I require this as the application will be developed

Data Pull vs. Push OOP Approach

我怕爱的太早我们不能终老 提交于 2019-12-03 02:18:04
问题 When I design my system from scratch, I often face a dilemma whether my object should push information into another objects OR whether the objects should pull the necessary data from another objects. Is there anything like a standard in OOP design, that I should prefer data pull by objects, versus data push into objects? Can anyone experienced advise, whether one approach is better over the other from longer term viewpoint , or when the OOP structure/framework/diagram gets more complex? 回答1:

how to implement observer pattern in javascript?

假装没事ソ 提交于 2019-12-03 01:45:15
问题 Hi I'm tyring to implement observer pattern in JavaScript: My index.js : $(document).ready(function () { var ironMan = new Movie(); ironMan.setTitle('IronMan'); ironMan.setRating('R'); ironMan.setId(1); // ironMan.setCast(['Robert Downey Jr.', 'Jeff Bridges', 'Gwyneth Paltrow']); var terminator = new Movie(); terminator.setTitle('Terminator'); terminator.setRating('P'); terminator.setId(2); console.log(ironMan.toString()); console.log(terminator.toString()); ironMan.play(); ironMan.stop();

C++11 observer pattern (signals, slots, events, change broadcaster/listener, or whatever you want to call it)

泪湿孤枕 提交于 2019-12-03 01:02:53
问题 With the changes made in C++11 (such as the inclusion of std::bind ), is there a recommended way to implement a simple single-threaded observer pattern without dependence on anything external to the core language or standard library (like boost::signal )? EDIT If someone could post some code showing how dependence on boost::signal could be reduced using new language features, that would still be very useful. 回答1: I think that bind makes it easier to create slots (cfr. the 'preferred' syntax

Difference between Observer Pattern and Event-Driven Approach

好久不见. 提交于 2019-12-03 01:00:32
问题 I always found the Observer Pattern almost similar to the usual event-driven approach. Actually, I have almost believed that they are actually just different names referring to the same thing. They both use similar concepts to have something as a listener and even in the implementation, they are almost the same thing, that's to have a callback method/function to carry out an action. This is at least in Java. In other languages say Actionscript/Flex, the events are more user-friendly and may

Implementing Notifications in Rails

给你一囗甜甜゛ 提交于 2019-12-03 00:56:38
问题 In my application, I want to notify a user, when he/she is mentioned in a comment or a post. The user handle is @user_name , similar to Facebook . The database table for mentions looks like: Mention mentioned_by: user_id (foreign key) user_mentioned: user_id (foreign key) comment_id: (foreign key) post_id: (foreign key) I can't figure out a way to implement it though. How do Facebook / Twitter do it? What I decided to go with, was use ActiveRecord callbacks/ Observer design pattern and

How do you determine if an object (self) with a lot of properties has been changed?

感情迁移 提交于 2019-12-02 22:44:07
The short version of the question: I have a class with a ton of declared properties, and I want to keep track of whether or not there have been any changes to it so that when I call a save method on it, it doesn't write to the database when it isn't needed. How do I update an isDirty property without writing custom setters for all of the declared properties ? The longer version of the question: Let's say that I have a class like this: @interface MyObject : NSObject { @property (nonatomic, retain) NSString *myString; @property (nonatomic, assign) BOOL myBool; // ... LOTS more properties

Multithreaded Observer Pattern [closed]

你说的曾经没有我的故事 提交于 2019-12-02 21:21:52
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 of a subject that gets updated very frequently. While the subject is updating the observers, "subject" object is locked and hence cannot be updated by a different thread. This will either create information traffic for subject or cause loss of information. Do you have any idea how these issues are handled in a