observer-pattern

How can I update information in an Android Activity from a background Service

☆樱花仙子☆ 提交于 2019-11-27 02:44:27
I am trying to create a simple Android application that has a ActivityList of information, when the application starts, I plan to start a Service that will be constantly calculating the data (it will be changing) and I want the ActivityList to be in sync with the data that the service is calculating for the life of the app. How can I set up my Activity to be listening to the Service? Is this the best way to approach this problem? For example, if you imagine a list of stock prices - the data would be being changed regularly and need to be in sync with the (in my case) Service that is

Python Observer Pattern: Examples, Tips? [closed]

百般思念 提交于 2019-11-27 02:42:06
Are there any exemplary examples of the GoF Observer implemented in Python? I have a bit code which currently has bits of debugging code laced through the key class (currently generating messages to stderr if a magic env is set). Additionally, the class has an interface for incrementally return results as well as storing them (in memory) for post processing. (The class itself is a job manager for concurrently executing commands on remote machines over ssh). Currently the usage of the class looks something like: job = SSHJobMan(hostlist, cmd) job.start() while not job.done(): for each in job

Magento - customer_save_after always fired twice

对着背影说爱祢 提交于 2019-11-27 01:42:16
问题 I am using the customer_save_after event in magento, and all is working fine apart from 1 annoying thing - it is always fired twice. There are no other modules rewriting this and I can find no other reason for this happening. When I look through all of the events getting fired at this time and this event is definately getting fired twice. Anyone explain this? I am writing a web service that hooks into this and its turning out to be quite inefficient to duplicate things. 回答1: I've noticed this

Is there a recommended way to use the Observer pattern in MVP using GWT?

我只是一个虾纸丫 提交于 2019-11-27 00:23:29
I am thinking about implementing a user interface according to the MVP pattern using GWT, but have doubts about how to proceed. These are (some of) my goals: the presenter knows nothing about the UI technology (i.e. uses nothing from com.google.*) the view knows nothing about the presenter (not sure yet if I'd like it to be model-agnostic, yet) the model knows nothing of the view or the presenter (...obviously) I would place an interface between the view and the presenter and use the Observer pattern to decouple the two: the view generates events and the presenter gets notified. What confuses

How to create custom event in symfony2

余生长醉 提交于 2019-11-27 00:14:08
问题 I want to create custom events called user_logged so that i can attach my listeners to those events. I want to execute few functions whenever user has logged in. 回答1: Create a class which extends Symfony\Component\EventDispatcher\Event . Then, use the event dispatcher service to dispatch the event: $eventDispatcher = $container->get('event_dispatcher'); $eventDispatcher->dispatch('custom.event.identifier', $event); You can register your event listener service like so: tags: - { name: kernel

Observer Design Pattern vs “Listeners”

扶醉桌前 提交于 2019-11-26 23:56:10
问题 It seems to me that the Observer design pattern as described in GOF is really the same thing as Listeners found in various toolkits. Is there a difference between the concepts, or are Listeners and Observers really the same thing. (I'm not looking for any specific computer language implementation, I just want to understand the difference (if any) from a design point of view. Yes, I know there are several answers to similar questions on SOF, but they're rooted in specific questions about

Difference between Observer, Pub/Sub, and Data Binding

不羁岁月 提交于 2019-11-26 23:45:11
问题 What is the difference between the Observer Pattern , Publish/Subscribe , and Data Binding ? I searched around a bit on Stack Overflow and did not find any good answers. What I have come to believe is that data binding is a generic term and there are different ways of implementing it such as the Observer Pattern or the Pub/Sub pattern. With the Observer pattern, an Observable updates its Observers. With Pub/Sub, 0-many publishers can publish messages of certain classes and 0-many subscribers

Observer design pattern in C++

余生长醉 提交于 2019-11-26 23:11:11
问题 Is the observer design pattern already defined in STL (Like the java.util.Observer and java.util.Observable in Java) ? 回答1: Here is a reference implementation (from Wikipedia). #include <iostream> #include <string> #include <map> #include <boost/foreach.hpp> class SupervisedString; class IObserver{ public: virtual void handleEvent(const SupervisedString&) = 0; }; class SupervisedString{ // Observable class std::string _str; std::map<IObserver* const, IObserver* const> _observers; typedef std:

Is there an event for customer account registration in Magento?

青春壹個敷衍的年華 提交于 2019-11-26 22:39:16
问题 I would like to be able to run some functionality with a module that I am building whenever a customer registers an account, but I can't seem to find any event that is fired upon a new customer registration . Does anybody know of an event that is dispatched for that? 回答1: Whenever I'm looking for an event, I'll temporarily edit the Mage.php file to output all the events for a particular request. File: app/Mage.php public static function dispatchEvent($name, array $data = array()) { Mage::log(

Determine what attributes were changed in Rails after_save callback?

倖福魔咒の 提交于 2019-11-26 22:30:39
问题 I'm setting up an after_save callback in my model observer to send a notification only if the model's published attribute was changed from false to true. Since methods such as changed? are only useful before the model is saved, the way I'm currently (and unsuccessfully) trying to do so is as follows: def before_save(blog) @og_published = blog.published? end def after_save(blog) if @og_published == false and blog.published? == true Notification.send(...) end end Does anyone have any