observer-pattern

The Observer Pattern - further considerations and generalised C++ implementation

被刻印的时光 ゝ 提交于 2019-12-20 08:51:20
问题 A C++ MVC framework I’m writing makes heavy use of the observer pattern. I have had a thorough read of the related chapter in Design Patterns (GoF, 1995) and had a look at a multitude of implementations in articles and existing libraries (including Boost). But as I was implementing the pattern, I could not help the feeling that there must be a better way - my client code involved lines and snippets that I felt should have been refactored into the pattern itself, if only I could find a way to

Vaadin 7 fire custom events between components

泄露秘密 提交于 2019-12-20 02:34:24
问题 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

Java Observer/Observable pattern does not Notify

ε祈祈猫儿з 提交于 2019-12-19 10:49:14
问题 I am trying to build a simple Java application with SWT using the MVC pattern. I would like to be able to automatically update the view when something happens in the background so I am trying to use the Observer/Observable pattern, but it looks like my Observer is never notified when my Observable changes. Here is the code: Launcher.java (main class) public class Launcher { public static void main(String[] args) { Application app = new Application(); PenguinView v = new PenguinView(app);

Ruby: automatically wrapping methods in event triggers

China☆狼群 提交于 2019-12-19 10:17:37
问题 Heres what I have/want: module Observable def observers; @observers; end def trigger(event, *args) good = true return good unless (@observers ||= {})[event] @obersvers[event].each { |e| good = false and break unless e.call(self, args) } good end def on(event, &block) @obersvers ||= {} @obersvers[event] ||= [] @observers[event] << block end end class Item < Thing include Observable def pickup(pickuper) return unless trigger(:before_pick_up, pickuper) pickuper.add_to_pocket self trigger(:after

How to get the current_user in a model observer?

二次信任 提交于 2019-12-19 07:48:49
问题 Given the following models: Room (id, title) RoomMembers (id, room_id) RoomFeed, also an observer When a Room title is updated, I want to create a RoomFeed item, showing who the user is who made the update. @room.update_attributes(:title => "This is my new title") Problem is in my observer for RoomFeed: def after_update(record) # record is the Room object end The is no way for me to get the user.id of the person who just made the update. How do I go about doing that? is there a better way to

content://sms/sent/ not working

旧时模样 提交于 2019-12-18 16:49:36
问题 This is the SMS observer code. I need to check only sent sms. When I use the content://sms/ I get the result. But why don't I get results when I use the content://sms/sent/ ? I'm using Android 2.1. import android.app.Service; import android.content.ContentResolver; import android.content.Intent; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.util.Log; public class

content://sms/sent/ not working

ε祈祈猫儿з 提交于 2019-12-18 16:49:11
问题 This is the SMS observer code. I need to check only sent sms. When I use the content://sms/ I get the result. But why don't I get results when I use the content://sms/sent/ ? I'm using Android 2.1. import android.app.Service; import android.content.ContentResolver; import android.content.Intent; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.util.Log; public class

How to create a full Audit log in Rails for every table?

混江龙づ霸主 提交于 2019-12-17 21:52:48
问题 We recently began a compliance push at our company and are required to keep a full history of changes to our data which is currently managed in a Rails application. We've been given the OK to simply push something descriptive for every action to a log file, which is a fairly unobtrusive way to go. My inclination is to do something like this in ApplicationController : around_filter :set_logger_username def set_logger_username Thread.current["username"] = current_user.login || "guest" yield

Observing change in frame of a UIView during animation

纵饮孤独 提交于 2019-12-17 18:55:26
问题 I want to observe changes to the x coordinate of my UIView's origin while it is being animated using animateWithDuration:delay:options:animations:completion: . I want to track changes in the x coordinate during this animation at a granular level because I want to make a change in interaction to another view that the view being animated may make contact with. I want to make that change at the exact point of contact. I want to understand the best way to do something like this at a higher level:

Getting error for generic interface: The interface Observer cannot be implemented more than once with different arguments:

纵饮孤独 提交于 2019-12-17 16:57:13
问题 I am getting this error in Eclipse while writing a GWT app The interface Observer cannot be implemented more than once with different arguments: Observer<CompositeListData > and Observer<DialogBoxAuthenticate> public class CompositeWordLists extends Composite implements Observer<DialogBoxAuthenticate>, Observer<CompositeListData> Here is the interface public interface Observer<T> { public void update(T o); } Is this right? How can I get around this problem without having to create a multitude