observer-pattern

C# Plugin Architecture with interfaces share between plugins

僤鯓⒐⒋嵵緔 提交于 2019-12-17 15:34:52
问题 I divided my problem into a short and a long version for the people with little time at hand. Short version: I need some architecture for a system with provider and consumer plugins. Providers should implement intereface IProvider and consumers should implement IConsumer. The executing application should only be aware of IProvider and IConsumer. A consumer implementation can ask the executing assembly (by means of a ServiceProcessor) which providers implement InterfaceX and gets a List back.

Implementing a callback in Python - passing a callable reference to the current function

寵の児 提交于 2019-12-17 15:23:27
问题 I want to implement the Observable pattern in Python for a couple of workers, and came across this helpful snippet: class Event(object): pass class Observable(object): def __init__(self): self.callbacks = [] def subscribe(self, callback): self.callbacks.append(callback) def fire(self, **attrs): e = Event() e.source = self for k, v in attrs.iteritems(): setattr(e, k, v) for fn in self.callbacks: fn(e) Source: Here As i understand it, in order to subscribe , I would need to pass a callback to

Android: Delete SMS at particular threadId location

江枫思渺然 提交于 2019-12-14 02:32:54
问题 I am trying to understand the difference between phones, and the software on them. I code and test on the Droid Incredible. A content observer of content://sms works fine and I am able to delete threadIds on the Incredible, but my app crashes on the Moto Droid Milestone. I test for the Milestone using Moto Dev Studio using the Milestone emulator package. It works fine in the emulator, but not on the actual device. Why would content://sms work fine on the Incredible, but not on the Milestone?

How do I know the generic object that the Observer class sends in Java?

泪湿孤枕 提交于 2019-12-13 12:43:34
问题 I am implementing the Observer / Observable pattern using Java. However, I am encountering a problem in the Observer portion of my code. Observable public class Model extends Observable { public void notify() { this.setChanged(); this.notifyObservers(new ArrayList<A>()); this.notifyObservers(new ArrayList<B>()); } } Observer public class View implements Observer { @Override public void update(Observable observable, Object object) { // TODO: If object is ArrayList<A>? System.out.println("A");

Implementing Observer pattern when observers wish to observe different items

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 12:18:28
问题 Below I have attempted to write a sudo code for the Observer pattern when observers wish to observe different items. Ignore the syntax errors. I wish to know if this is the correct way to implement this. If not, please suggest better ways. // Used by the subject for keeping a track of what items the observer wants to observe typedef struct observerListStruct { bool getTemperatureUpdate; bool getHumidityUpdate; bool getPressureUpdate; observer's-function pointer's address; }; // Subject's

Android ViewModel: Should I “borrow” the observe() method from LiveData like in the official example?

孤人 提交于 2019-12-13 10:29:26
问题 When working with ViewModels the View observes the ViewModel. It has to register as an observer. In the official tutorial of Google this registration is delegated to the observe() method of a LiveData object. public class MyViewModel extends ViewModel { private MutableLiveData<List<User>> users; public LiveData<List<User>> getUsers() { if (users == null) { users = new MutableLiveData<List<Users>>(); loadUsers(); } return users; } private void loadUsers() { // Do an asynchronous operation to

Observable do not receive the next value in angular2

こ雲淡風輕ζ 提交于 2019-12-13 06:26:31
问题 In order to pass value between angular2 different components, I use different services injected into different components. In my PagesService component, I define a behavior subject and want to pass a value. import { Injectable } from '@angular/core'; import { ApiService } from '../../apiService/api.service'; import { Playlists } from '../shared/playlists.model'; import { Subject, BehaviorSubject } from 'rxjs/Rx'; @Injectable() export class PagesService { private currentPlaylists: Subject

Data structure: Is there something like a two way observer pattern?

我与影子孤独终老i 提交于 2019-12-13 06:01:11
问题 So I have a scenario like this with classes Student and Course Student A is enrolled in Course 1, 2 Student B is enrolled in Course 1, 2, 3 Student C is enrolled in Course 2 So there are two kinds of events: Student A is deleted -> need to notify two objects: Course 1 and Course 2 Course 1 is canceled -> need to notify two objects: Student A and Student B I know that the Observer pattern can work if each Student can be only enrolled in 1 Course, in which case I have a list of Student for each

jboss - tomcat deploy listener

孤人 提交于 2019-12-13 02:59:56
问题 I got a requirement to write a log line when all wars have been deployed. Is there an observer pattern for Tomcat's deployer I could hook onto? On first start jBoss/Tomcat send out a line with exact time spent on startup. Not perfect... but works. But on hot deploy no notification/log is sent/written :( (There are around 100 servlets in the project and it's a risk to list them all in order and then guess that the deployment is finished once the last one initializes, so let's try to skip

C++ safe idiom to call a member function of a class through a shared_ptr class member

耗尽温柔 提交于 2019-12-13 02:55:30
问题 Problem description In designing an observer pattern for my code, I encountered the following task: I have a class Observer which contains a variable std::shared_ptr<Receiver> and I want to use a weak_ptr<Receiver> to this shared-pointer to safely call a function update() in Observer (for a more detailed motivation including some profiling measurements, see the EDIT below). Here is an example code: struct Receiver { void call_update_in_observer() { /* how to implement this function? */} };