observer-pattern

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

蓝咒 提交于 2019-11-26 12:35:13
问题 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

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

穿精又带淫゛_ 提交于 2019-11-26 12:22:37
问题 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

Observe a File or Folder in Objective-C

一世执手 提交于 2019-11-26 12:04:54
问题 What is the best way to listen to a folder or file to see if it has been saved or if a new file has been added? 回答1: The FSEvents API is ideal if you just want to watch directories but it doesn't handle the monitoring of individual files. Stu Connolly has a great Objective-C wrapper for the FSEvents C API, it's called SCEvents and you can get it here: http://stuconnolly.com/blog/scevents-011/ The nice thing about FSEvents is that you just need to watch one folder and you will be notified of

When should we use Observer and Observable?

若如初见. 提交于 2019-11-26 11:59:13
An interviewer asked me: What is Observer and Observable and when should we use them? I wasn't aware of these terms, so when I got back home and started Googling about Observer and Observable , I found some points from different resources: 1) Observable is a class and Observer is an interface. 2) The Observable class maintains a list of Observer s. 3) When an Observable object is updated, it invokes the update() method of each of its Observer s to notify that, it is changed. I found this example: import java.util.Observable; import java.util.Observer; class MessageBoard extends Observable {

pass function in json and execute

旧城冷巷雨未停 提交于 2019-11-26 10:49:17
问题 Is there any way that I can pass a function as a json string (conversion with JSON.stringify), send it to another function, parse the json and then execute the function that was in the json? I am using jquery and javascript. 回答1: Here's a working example Basically, you have to be careful with this sort of thing. If you take an extant javascript function, turn it to a string, and eval it, you might run into function redeclaration issues. If you are simply taking a function string from the

Leveraging the observer pattern in JavaFX GUI design

回眸只為那壹抹淺笑 提交于 2019-11-26 07:49:54
问题 As noted here in the context of Swing, GUI design makes frequent use of the observer pattern. Having frequently used the scheme prescribed in EventListenerList, is there a Java FX example, such as Converter, that focuses on the pattern itself? 回答1: As noted here, the JavaFX architecture tends to favor binding GUI elements via classes that implement the Observable interface. Toward this end, Irina Fedortsova has adapted the original Converter to JavaFX in Chapter 5 of JavaFX for Swing

How to trigger function on value change?

两盒软妹~` 提交于 2019-11-26 07:23:08
问题 I realise this question has to do with event-handling and i\'ve read about Python event-handler a dispatchers, so either it did not answer my question or i completely missed out the information. I want method m() of object A to be triggered whenever value v is changing: For instance (assuming money makes happy): global_wealth = 0 class Person() def __init__(self): self.wealth = 0 global global_wealth # here is where attribute should be # bound to changes in \'global_wealth\' self.happiness =

Super-simple example of C# observer/observable with delegates

非 Y 不嫁゛ 提交于 2019-11-26 04:29:26
问题 I recently started digging into C# but I can\'t by my life figure out how delegates work when implementing the observer/observable pattern in the language. Could someone give me a super-simple example of how it is done? I have googled this, but all of the examples I found were either too problem-specific or too \"bloated\". 回答1: The observer pattern is usually implemented with events. Here's an example: using System; class Observable { public event EventHandler SomethingHappened; public void

When should we use Observer and Observable?

别等时光非礼了梦想. 提交于 2019-11-26 02:39:38
问题 An interviewer asked me: What is Observer and Observable and when should we use them? I wasn\'t aware of these terms, so when I got back home and started Googling about Observer and Observable , I found some points from different resources: 1) Observable is a class and Observer is an interface. 2) The Observable class maintains a list of Observer s. 3) When an Observable object is updated, it invokes the update() method of each of its Observer s to notify that, it is changed. I found this

Delegation: EventEmitter or Observable in Angular

ぃ、小莉子 提交于 2019-11-25 21:47:28
问题 I am trying to implement something like a delegation pattern in Angular. When the user clicks on a nav-item , I would like to call a function which then emits an event which should in turn be handled by some other component listening for the event. Here is the scenario: I have a Navigation component: import {Component, Output, EventEmitter} from \'angular2/core\'; @Component({ // other properties left out for brevity events : [\'navchange\'], template:` <div class=\"nav-item\" (click)=\