problem about observer-pattern-Collection of common programming errors
Rodion Gorkovenko
java events design-patterns listener observer-pattern
There are several incarnations of Observer pattern: Listeners, Events etc. (am I right?)But today we found we have no agreement among team members – is it possible that Listener (Observer) affect execution of the method which invokes it. The example was proposed as following: when the deal is saved via DealDao, it could fire an event which would be caught by some Listener which will:update calculated fields in the deal (some fees etc.); create some dependent entities.I myself greatly dislik
remi bourgarel
design-patterns decorator observer-pattern
There is these two pattern : observer and decorator. Both enables me to add an action after something was done (or before for the decorator). But their implementation differs. So when should I use a decorator or an observer.So far I came up with this :decorator : add business functionnality to a service that’ll change the state of the entities used by the decorated service. observer : update the view model / gui, connect with infrastructure service, change the state of other entitiesFor instance
Emerion
c# design-patterns observer-pattern
ok, so I am stuck at the observer pattern here, almost all tutorials I read tell the subject class to subscribe the observer(s).But with encapsulation in mind, how is this not tighlty coupled? They still depend on each other know, don’t they?What I mean to say is that the subject Class must know the observer object to add him to the list of objects to notify.Therefore a dependency is created, right?What’s the mistake I make?Thanks!Thanks everybody for the replies,Now I have some new questions. I
jWeaver
java class interface observer-pattern observable
The Interviewer asked to me, What is Observer and Observable and when we used these? Since, I heard these term first time ever. So, I simply said Sorry. When I came back to home. I start searching about Observer and Observable and found some point from different resources :1.) Observable is a Class and Observer is an Interface2.) Observable class maintain a list of observers3.) When an Observable object is updated it invokes the update() method of each of its observers to notify that, it is chan
Jeff Martin
.net design-patterns events observer-pattern
I am a senior level developer but I haven’t had a lot of formal training and I although I have used many design patterns and seen them used in my years as a developer, no one really went out of their way to say. “Oh this is an observer pattern, or this is a Singleton pattern.”Reading over some of the design patterns, I came across the Observer pattern and it seems to be to be very similar to the way the .NET framework events work. Am I missing something fundamental about this?
Bill the Lizard
c# design-patterns observer-pattern
Currently, my level of understanding is below all the coding examples on the web about the Observer Pattern. I understand it simply as being almost a subscription that updates all other events when a change is made that the delegate registers. However, I’m very unstable in my true comprehension of the benefits and uses. I’ve done some googling, but most are above my level of understanding. I’m trying to implement this pattern with my current homework assignment, and to truly make sense on my pro
Halo
java mvc observer-pattern listeners
My model in my MVC pattern, generates components at runtime and gives them to the View to be displayed on the screen through update() method (you know, model is the observable and the view is the observer). But I also need to add listeners to these components, and the controller has the listener methods (because they say the MVC pattern is like this) and it’s not involved in this update process. So I can’t add the listeners at runtime, but only in the controller’s constructor at startup.I’ve got
David Hinkes
soa observer-pattern middleware publish-subscribe mom
I’m in the market for a good open source network based Pub/Sub (observer pattern) library. I haven’t found any I like:JMS – tied to Java, treats message contents as dumb binary blobs NDDS – $$, use of IDL CORBA/ICE – Pub/Sub is built on-top of RPC, CORBA API is non-intuitive JBOSS/ESB – not too familiar withIt would be nice if such a package could to the following:Network based Aware of payload data, users should not have to worry about endian/serialization issues Multiple language support (C+
Mark Rushakoff
garbage-collection observer-pattern
In a GC enabled language, when observer subscribes to events of subject, actually subject got a reference of observer.So before drop an observer, it must un-subscribes first. Other wise, because it’s still referenced by subject, it will never be garbage collected.Normally there are 3 solutions:Manually un-subscribes Weak Reference.Both of them cause other problems.So usually I don’t like to use observer patterns, but I still can not find any replacement for that.I mean, this pattern describes
hbrlovehaku
design-patterns observer-pattern publish-subscribe
I have 2 programs A, B. If A finishes, I want B to know that and start to run, using data from result of A.A is a .NET web application. I think that’s not kept alive in memory all the time, right? Only alive if requested from browsers, right?Before, A and B are the 2 functions of the same program. But B program fails sometimes due to business reasons. And even if B doesn’t fail, it’s time-consuming and makes the clients wait for too long and be unhappy. So I separated B out. Clients using A smoo
js_
iphone objective-c ios observer-pattern
I’m uisng addObserver:selector:name:object: in viewDidLoad.And I’m using removeObserver:name:object: in viewWillDisappear:animated: to remove observer.What will happen if I failed to remove observer by passing wrong parameter to removeObserver:name:object:? (For example, observer isn’t removed if I pass wrong notification to parameter name or wrong object to object or Observer)If the observer still not nil after calling removeObserver:name:object:, I can find out that removing observer failed be
minhaz
java android multithreading observer-pattern
getting a strange null pointer exception for a common type of custom listener that i have implemented before without any problems.a crash will happen if i put any code in the callback method that communicates with the main user interface thread of the activity. if i put any code inside this method that does not touch the user interface thread then there is no crash. it does not make sense because all the code in this class runs on the UI thread and does not need to use a handler or runonui met
jsevilleja
java singleton design-patterns observer-pattern
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?
Amandir
iphone core-data observer-pattern
I am running into another problem with my Iphone App which I just can’t solve myself. I implemented a kind of organizer functionality in my latest app. There one can create appointments which are displayed in a tableview and persisted in a CoreDataStore. I use 4 classes:an overview where appointments are displayed a view with textfields to put in Values for place and name of appointment (create/edit view) a view with DatePicker to define start- and enddate a controller which handles creation a
charliepark
ruby-on-rails model observer-pattern sweeper
I’m working on a Rails app, where I’m using page caching to store static html output. The caching works fine. I’m having trouble expiring the caches, though.I believe my problem is, in part, because I’m not expiring the cache from my controller. All of the actions necessary for this are being handled within the model. This seems like it should be doable, but all of the references to Model-based cache expiration that I’m finding seem to be out of date, or are otherwise not working.In my environme
KARASZI István
ruby-on-rails activerecord observer-pattern extending
I have extended the ActiveRecord::Base class in the following way:I made a directory under the lib, let’s call it now foo wrote the module which provides the extra method has_many_bidirectional to have bidirectional has_many relationships in ActiveRecord::Base classes in the lib/foo/active_record.rb:module Foomodule ActiveRecordautoload :Associations, ‘active_record/associations’autoload :Base, ‘active_record/base’end endin the lib/foo/active_record/base.rb:module Foomodule ActiveRecordmodule B
Amit Erandole
jquery-ui publish-subscribe observer-pattern
I am creating a calculator based on the jQuery UI range slider and have a setup that works. I have a bindEvents function in my application that binds the slider to the slide event:// this is where I bind all slide eventsbindEvents: function() {// hold on to the value of thisvar self = CloudCalc;// bind the slider’s slide event to a data eventself.sl.on(‘slide’, this.setSliderOutputValue); }and then here is the handler that faithfully executes my event:setSliderOutputValue: function (
jparthj
javascript design-patterns observer-pattern publish-subscribe
I am trying to understand the Observable/Observer design pattern.This is the code I have so far (code from Javascript Patterns book):var publisher = {subscribers: {any: [] // event type: subscribers},publications: {any: []},subscribe: function (fn, type) {type = type || ‘any’;if (typeof this.subscribers[type] === “undefined”) {this.subscribers[type] = [];}this.subscribers[type].push(fn);if(typeof this.publications[type] === “undefined”){return;}var pubs = this.publications[type],i,max = pubs.len
brewster
ruby-on-rails forms observer-pattern
i cannot seem to get observe_form to call a particular actioni have a route definedmap.resources :charges, :collection => {:charge_total => :get}my controllerclass ChargesController < ApplicationControllerdef charge_totalreturn ‘foo’end endmy view: i have tried both…observe_form form_id, :update => :charge_total, :url => :charge_total_chargesandobserve_form form_id, :update => :charge_total, :url => {:controller => :charges, :action => :charge_total}when the form upd
user1074896
java observer-pattern
Can I use observer pattern for error handling? What are adv/disadvantages of it? Does anybody use this approach for this purpose?UPDATE:class MyErrorApi{ public static final int NETWORK_ERROR = 1;public(MyErrorApi error){ … } }interface ErrorListener{ void onErrorOcurred(MyErrorApi arror) }class MyBaseScreen implements ErrorListener{void onErrorOcurred(MyErrorApi arror){ swirch(arror){ **showPopup();** ….. } }
Web site is in building