observer-pattern

Difference between Observer Pattern and Event-Driven Approach

假装没事ソ 提交于 2019-12-02 14:21:38
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 look like it does more than just the observer pattern defines. But still, the concepts sound the same.

Implementing Notifications in Rails

与世无争的帅哥 提交于 2019-12-02 14:19:22
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 whenever a new comment/post is saved to database, I can go through the contents of the post/comment, and look

Data Pull vs. Push OOP Approach

浪子不回头ぞ 提交于 2019-12-02 14:14:49
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? According to tell dont ask , push is better - or more OO. You don't want to query object for data so you can

Can an observable class be constructed as a singleton?

雨燕双飞 提交于 2019-12-02 10:54:06
I'm making a program in Java with the Observer pattern (with the help of the Java API). If some of the observables had more than one instance, the program could crash. Should I implement them as singleton? Is it recommended? I did it before and didn't have any problems exactly because I used a singleton. The pattern is there to use it. Should I implement them as singleton? Is it recommended? Of course you can do this. Whether it is a good idea depends on the actual context. Are these things conceptually singleton, or is this just a hack to try to make bugs disappear? (Or to put it another way,

Using an observer within an Engine

荒凉一梦 提交于 2019-12-02 06:16:09
I've created an Engine which is basically used for all of our projects. Now what I want to do is add a before_create callback to all of the models in this Engine. After some searching I found out that an observer is the way to go. So, I've created this observer: # app/models/baco/auth/auth_observer class Baco::Auth::AuthObserver < ActiveRecord::Observer def before_create( record ) p record end end And now I need to add it to the application, but of course in my Engine there is no such file as application.rb, so I've placed it in my engine: # lib/baco/auth/engine.rb require 'rails' require

Vaadin 7 fire custom events between components

允我心安 提交于 2019-12-01 21:02:01
I want to create custom events and fire them in some part of the view such that some other part of the view is updated/removed/refreshed. I have tried by extending the Component.Event and Component.Listener but it doesn't work. I think that events and listeners mustbe limited to the same component instance. Can this be done with Vaadin 7? Basically I want to decouple my views and provide easy communication between components. I'm also using Spring with Vaadin. If you have better ideas beside the Observer pattern I would also appreciate it. Thank you vlad2005 What you need: 1. A component that

selective D-BUS signal emitting from ObServer (unicast signal)

微笑、不失礼 提交于 2019-12-01 11:28:52
I have a situation where I have a single ObServer object and a set of Clients. ObServer and clients connected through D-BUS (IPC). ObServer has generic interface for all clients. But, time to time ObServer needs to notify clients about some events. Clients listen for a ObServer Generic interface signal OnNotify(). Question: How to emit D-BUS signal (OnNotify()) from ObServer to specified client (instead of broadcast to all) ? p.s Qt D-BUS used for wrapping but any approach are welcome. You can't. Signals are received by all clients that have registered for that signal on a DBus interface. You

R shiny - last clicked button id

北慕城南 提交于 2019-12-01 10:35:14
I have multiple action buttons, on which i want to show different select Inputs and I want to know last clicked button id, how can I do that? When I use which(lapply(c(1:10), function(i) { input[[paste0("ActionButton", i)]]}) == TRUE) It shows me all button which were clicked, however I want to know which one was the last in order to enable click once again on previous buttons. How can I do that? I am new in shiny and not sure if understand all reactive/isolate issue so I would be greateful for any hints. You can do it by adding JS smthing like $(document).on('click', '.needed', function () {

R shiny - last clicked button id

北慕城南 提交于 2019-12-01 08:21:00
问题 I have multiple action buttons, on which i want to show different select Inputs and I want to know last clicked button id, how can I do that? When I use which(lapply(c(1:10), function(i) { input[[paste0("ActionButton", i)]]}) == TRUE) It shows me all button which were clicked, however I want to know which one was the last in order to enable click once again on previous buttons. How can I do that? I am new in shiny and not sure if understand all reactive/isolate issue so I would be greateful

selective D-BUS signal emitting from ObServer (unicast signal)

流过昼夜 提交于 2019-12-01 08:07:36
问题 I have a situation where I have a single ObServer object and a set of Clients. ObServer and clients connected through D-BUS (IPC). ObServer has generic interface for all clients. But, time to time ObServer needs to notify clients about some events. Clients listen for a ObServer Generic interface signal OnNotify(). Question: How to emit D-BUS signal (OnNotify()) from ObServer to specified client (instead of broadcast to all) ? p.s Qt D-BUS used for wrapping but any approach are welcome. 回答1: