Search Results

Search found 237 results on 10 pages for 'observer'.

Page 1/10 | 1 2 3 4 5 6 7 8 9 10  | Next Page >

  • A talk about observer pattern

    - by Martin
    As part of a university course I'm taking, I have to hold a 10 minute talk about the observer pattern. So far these are my points: What is it? (defenition) Polling is an alternative Polling VS Observer When Observer is better When Polling is better (taken from here) A statement that Mediator pattern is worth checking out. (I won't have time to cover it in 10 minutes) I would be happy to hear about: Any suggestions to add something? Another alternative (if exists)

    Read the article

  • Adding an observer to UIImageView? observer & notifications

    - by sagar
    Each class has almost one method named addObserver [imgVURL addObserver:<#(NSObject *)observer#> forKeyPath:<#(NSString *)keyPath#> options:<#(NSKeyValueObservingOptions)options#> context:<#(void *)context#>] Here, imgVURL is an image which is going to be load an image asynchronously. When image will be loaded dynamically - other class will set an image from loaded data. Now, my question is how can we add an observer to UIImageView's instance. Observer and notifications are same or not ? If it is not then what's different ? Let's have some sample code That I did in my project to understand my question. // locating image view from Scroll view by it's tag imgVURL=(UIImageView*)[scrMain viewWithTag:(kTagImagesTag+i)]; // ImageViewURL is a class which contains methods of // didReceiveResponse // didReceiveData // connection ImageViewURL *tmp=[[ImageViewURL alloc] init]; // it has a nonatomic property which will take the reference of my image view tmp.imgV=imgVURL; // now I will pass a url from my an array to property strURL // in strUrl I have custom setter // in which I am initializing a connection tmp.strUrl=[NSURL URLWithString:[[tblmain objectAtIndex:i] valueForKey:@"url"]]; // from ImageViewURL.m file -(void)connectionDidFinishLoading:(NSURLConnection *)connection { [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; // NSLog@"ImageView Ref From - %@",imgV); // see imgV has reference of my -> imgVURL (nonatomic,assign) imgV.image=[UIImage imageWithData:myWebData]; [connection release]; connection=nil; } // as you can see in above code many many images are loaded asynchronously // now How can I add an observer to an imageview whether it received or not.

    Read the article

  • Observer pattern for unpredictable observation time

    - by JoJo
    I have a situation where objects are created at unpredictable times. Some of these objects are created before an important event, some after. If the event already happened, I make the object execute stuff right away. If the event is forthcoming, I make the object observe the event. When the event triggers, the object is notified and executes the same code. if (subject.eventAlreadyHappened()) { observer.executeStuff(); } else { subject.subscribe(observer); } Is there another design pattern to wrap or even replace this observer pattern? I think it looks a little dirty to me.

    Read the article

  • What are the advantages of the delegate pattern over the observer pattern?

    - by JoJo
    In the delegate pattern, only one object can directly listen to another object's events. In the observer pattern, any number of objects can listen to a particular object's events. When designing a class that needs to notify other object(s) of events, why would you ever use the delegate pattern over the observer pattern? I see the observer pattern as more flexible. You may only have one observer now, but a future design may require multiple observers.

    Read the article

  • Using an observer within an Engine

    - by Tim
    I've created an Engine which is basically used for all of our projects. Now what I want to do is add a before_create callback to all of the models in this Engine. After some searching I found out that an observer is the way to go. So, I've created this observer: class AuthObserver < ActiveRecord::Observer def before_create( record ) p record end end And now I need to add it to the application, but of course in my Engine there is no such file as application.rb. What I tried is adding it to an initializer located in /config/initializers/observers.rb Like so: Rails.application.config.active_record.observers = :auth_observer But this doesn't work, and it throws no errors. Anybody out here has experience using an observer inside an engine? Thanks a lot!

    Read the article

  • iPhone Key-Value Observer: observer not registering in UITableViewController

    - by Scott
    Hi Fellow iPhone Developers, I am an experienced software engineer but new to the iPhone platform. I have successfully implemented sub-classed view controllers and can push and pop parent/child views on the view controller stack. However, I have struck trouble while trying to update a view controller when an object is edited in a child view controller. After much failed experimentation, I discovered the key-value observer API which looked like the perfect way to do this. I then registered an observer in my main/parent view controller, and in the observer I intend to reload the view. The idea is that when the object is edited in the child view controller, this will be fired. However, I think that the observer is not being registered, because I know that the value is being updated in the editing view controller (I can see it in the debugger), but the observing method is never being called. Please help! Code snippets follow below. Object being observed. I believe that this is key-value compliant as the value is set when called with the setvalue message (see Child View Controller below). X.h: @interface X : NSObject <NSCoding> { NSString *name; ... @property (nonatomic, retain) NSString *name; X.m: @implementation X @synthesize name; ... Main View Controller.h: @class X; @interface XViewController : UITableViewController { X *x; ... Main View Controller.m: @implementation XViewController @synthesize x; ... - (void)viewDidLoad { ... [self.x addObserver:self forKeyPath: @"name" options: (NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil]; [super viewDidLoad]; } ... - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqual:@"name"]) { NSLog(@"Found change to X"); [self.tableView reloadData]; } [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } Child View Controller.m: (this correctly sets the value in the object in the child view controller) [self.x setValue:[[tempValues objectForKey:key] text] forKey:@"name"];

    Read the article

  • Is the Observer pattern adequate for this kind of scenario?

    - by Omega
    I'm creating a simple game development framework with Ruby. There is a node system. A node is a game entity, and it has position. It can have children nodes (and one parent node). Children are always drawn relatively to their parent. Nodes have a @position field. Anyone can modify it. When such position is modified, the node must update its children accordingly to properly draw them relatively to it. @position contains a Point instance (a class with x and y properties, plus some other useful methods). I need to know when a node's @position's state changes, so I can tell the node to update its children. This is easy if the programmer does something like this: @node.position = Point.new(300,300) Because it is equivalent to calling this: # Code in the Node class def position=(newValue) @position = newValue update_my_children # <--- I know that the position changed end But, I'm lost when this happens: @node.position.x = 300 The only one that knows that the position changed is the Point instance stored in the @position property of the node. But I need the node to be notified! It was at this point that I considered the Observer pattern. Basically, Point is now observable. When a node's position property is given a new Point instance (through the assignment operator), it will stop observing the previous Point it had (if any), and start observing the new one. When a Point instance gets a state change, all observers (the node owning it) will be notified, so now my node can update its children when the position changes. A problem is when this happens: @someNode.position = @anotherNode.position This means that two nodes are observing the same point. If I change one of the node's position, the other would change as well. To fix this, when a position is assigned, I plan to create a new Point instance, copy the passed argument's x and y, and store my newly created point instead of storing the passed one. Another problem I fear is this: somePoint = @node.position somePoint.x = 500 This would, technically, modify @node's position. I'm not sure if anyone would be expecting that behavior. I'm under the impression that people see Point as some kind of primitive rather than an actual object. Is this approach even reasonable? Reasons I'm feeling skeptical: I've heard that the Observer pattern should be used with, well, many observers. Technically, in this scenario there is only one observer at a time. When assigning a node's position as another's (@someNode.position = @anotherNode.position), where I create a whole new instance rather than storing the passed point, it feels hackish, or even inefficient.

    Read the article

  • Java Inter Application Form Communication Observer Pattern

    - by ikurtz
    Observer pattern? Where do i get examples of this in Java (i know google but was hoping for some personal insight also.) On to a proper explanation of my issue: i have 3 forms/windows. "board" is the main form that loads as the application. "chat" is where the text chat takes place. "network" is where network connection is established. i have the game (connect4) working locally and i would like to implement a networked version of it also. my idea is maybe it is related to Observer pattern to have a thread (or something) monitoring network state during runtime and update the chat and board forms of the current network status as well as delivering received data from the network. are my ideas valid? or how should i go about establishing network and network status updates throughout the application? thank you for your input.

    Read the article

  • rails arguments to after_save observer

    - by ash34
    Hi, I want users to enter a comma-delimited list of logins on the form, to be notified by email when a new comment/post is created. I don't want to store this list in the database so I would use a form_tag_helper 'text_area_tag' instead of a form helper text_field. I have an 'after_save' observer which should send an email when the comment/post is created. As far as I am aware, the after_save event only takes the model object as the argument, so how do I pass this non model backed list of logins to the observer to be passed on to the Mailer method that uses them in the cc list. thanks

    Read the article

  • How to handle data output in an Observer?

    - by Mannaz
    I have an Observable and an Observer. The observable does download some stuff in a background thread and calls notifyObservers to let the observers read the status. At some point in public void update the observer tries to updates the GUI ((TextView)findViewById('R.id.foo')).setText("bar"); but it seems like the observable thread calls this method, because the Observable (!!!) throws this: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRoot.checkThread(ViewRoot.java:2462) at android.view.ViewRoot.requestLayout(ViewRoot.java:512) ... at com.mynamespace.acitivty.TrackActivity.startPlay(TrackActivity.java:72) at com.mynamespace.acitivty.TrackActivity.update(TrackActivity.java:107) at java.util.Observable.notifyObservers(Observable.java:147) at java.util.Observable.notifyObservers(Observable.java:128) at com.mynamespace.module.communication.Download.stateChanged(Download.java:213) at com.mynamespace.module.communication.Download.run(Download.java:186) at java.lang.Thread.run(Thread.java:1058) Is there some way I can prevent this from happening? I'm sure I'm missing something obvious here.

    Read the article

  • Observer Design Pattern - multiple event types

    - by David
    I'm currently implementing the Observer design pattern and using it to handle adding items to the session, create error logs and write messages out to the user giving feedback on their actions (e.g. You've just logged out!). I began with a single method on the subject called addEvent() but as I added more Observers I found that the parameters required to detail all the information I needed for each listener began to grow. I now have 3 methods called addMessage(), addStorage() and addLog(). These add data into an events array that has a key related to the event type (e.g. log, message, storage) but I'm starting to feel that now the subject needs to know too much about the listeners that are attached. My alternative thought is to go back to addEvent() and pass an event type (e.g. USER_LOGOUT) along with the data associated and each Observer maintains it's own list of event handles it is looking for (possibly in a switch statement), but this feels cumbersome. Also, I'd need to check that sufficient data had also been passed along with the event type. What is the correct way of doing this? Please let me know if I can explain any parts of this further. I hope you can help and see the problem I'm battling with.

    Read the article

  • Rosetta Stone: Observer Pattern

    - by Shiftbit
    How is the Observer Pattern expressed in various programming languages? Can you provide a code snippet that illustrates the major differences in each language. This post is intended to demonstrate the differences of this commonly used design pattern. I will start this off with a Java example. Remember to start your answer off with the language being demonstrated.

    Read the article

  • 'click' observer in Prototype

    - by Tom
    I have a page which contains several divs (each with a unique ID and the same class, 'parent'). Underneath each "parent" div, is a div with class "child" and unique ID name -child. This DIV is upon page load empty. Whenever you click on a parent DIV, the following code is executed. $$('div.parent').each(function(s){ $(s).observe('click', function(event){ event.stop(); var filer = $(s).readAttribute('filer'); var currentElement = $(s).id; var childElement = currentElement + '-children'; new Ajax.Updater ({success: childElement}, root + '/filers/interfacechildren', { parameters: {parentId: currentElement, filer: filer} }); }); }); Of course, it's possible that a child node is again a parent ont its own. The response looks like this (Smarty with Zend Framework): {foreach from=$ifaces item=interface} <div id="{$interface->name}" filer="{$interface->system_id}" class="parent">{$interface->name}</div> <div id="{$interface->name}-children" class="child"></div> {/foreach} Whenever I click on a "parent" div that is loaded inside a child, nothing happens :( Any suggestions / fixes how to fix this?

    Read the article

  • XMLHttpRequest fails in observer method

    - by Michael
    I'm developing a Firefox extension and this code belongs to javascript module. var ajax = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); ajax.open('GET', "http://www.google.com", true); ajax.onload = function () { Reader.log("Got News"); }; ajax.onerror = function () { Reader.log("Got Error"); }; ajax.send(null); This small code always fails (onerror) if calling from observe method invoked by preference "@mozilla.org/preferences-service;1" Anyone knows how to make this work in observe method?

    Read the article

  • Cocoa document-based app: Notification not always received by observer

    - by roysolay
    Hi, I hope somebody can help with my notification problem. I have a notification which looks to be set up correctly but it isn’t delivered as expected. I am developing a document based app. The delegate/ document class posts the notification when it reads from a saved file: [[NSNotificationCenter defaultCenter] postNotificationName:notifyBsplinePolyOpened object:self]; Logging tells me that this line is reached whenever I open a saved document. In the DrawView class, I have observers for the windowOpen notification and the bsplinePoly file open notification: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainWindowOpen:) name:NSWindowDidBecomeMainNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(savedBspline:) name:notifyBsplinePolyOpened object:nil]; - (void) mainWindowOpen:(NSNotification*) note { NSLog(@"Window opened"); _mainWindow = [note object]; } - (void) savedBspline:(NSNotification*) note { NSLog(@"savedBspline called"); NSLog(@"note is %@", [note name]); } The behavior is odd. When I save and close the main window and reopen it, I get the “Window opened” message but not the “savedBspline called” message. If I leave a main window open and open a previously saved session, I get the “Window opened” message and the “savedBspline called” message. I have searched online discussion and Apple DevCenter documentation but I have not seen this problem.

    Read the article

  • Observer pattern used with decorator pattern

    - by icelated
    I want to make a program that does an order entry system for beverages. ( i will probably do description, cost) I want to use the Decorator pattern and the observer pattern. I made a UML drawing and saved it as a pic for easy viewing. This site wont let me upload as a word doc so i have to upload a pic - i hope its easily viewable.... I need to know if i am doing the UML / design patterns correctly before moving on to the coding part. Beverage is my abstract component class. Espresso, houseblend, darkroast are my concrete subject classes.. I also have a condiment decorator class milk,mocha,soy,whip. would be my observer? because they would be interested in data changes to cost? Now, would the espresso,houseblend etc, be my SUBJECT and the condiments be my observer? My theory is that Cost is a changes and that the condiments need to know the changes? So, subject = esspresso,houseblend,darkroast,etc.. // they hold cost() Observer = milk,mocha,soy,whip? // they hold cost() would be the concrete components and the milk,mocha,soy,whip? would be the decorator! So, following good software engineering practices "design to an interface and not implementation" or "identify things that change from those that dont" would i need a costbehavior interface? If you look at the UML you will see where i am going with this and see if i am implementing observer + Decorator pattern correctly? I think the decorator is correct. since, the pic is not very viewable i will detail the classes here: Beverage class(register observer, remove observer, notify observer, description) these classes are the concrete beverage classes espresso, houseblend,darkroast, decaf(cost,getdescription,setcost,costchanged) interface observer class(update) // cost? interface costbehavior class(cost) // since this changes? condiment decorator class( getdescription) concrete classes that are linked to the 2 interface s and decorator are: milk,mocha,soy,whip(cost,getdescription,update) these are my decorator/ wrapper classes. Thank you.. Is there a way to make this picture bigger?

    Read the article

  • Is there a design pattern for chained observers?

    - by sharakan
    Several times, I've found myself in a situation where I want to add functionality to an existing Observer-Observable relationship. For example, let's say I have an Observable class called PriceFeed, instances of which are created by a variety of PriceSources. Observers on this are notified whenever the underlying PriceSource updates the PriceFeed with a new price. Now I want to add a feature that allows a (temporary) override to be set on the PriceFeed. The PriceSource should still update prices on the PriceFeed, but for as long as the override is set, whenever a consumer asks PriceFeed for it's current value, it should get the override. The way I did this was to introduce a new OverrideablePriceFeed that is itself both an Observer and an Observable, and that decorates the actual PriceFeed. It's implementation of .getPrice() is straight from Chain of Responsibility, but how about the handling of Observable events? When an override is set or cleared, it should issue it's own event to Observers, as well as forwarding events from the underlying PriceFeed. I think of this as some kind of a chained observer, and was curious if there's a more definitive description of a similar pattern.

    Read the article

  • Observer Pattern Implementation

    - by user17028
    To teach myself basic game programming, I am going to program a clone of Pong. I will use the Observer design pattern, with an interface between the input and the game engine. However, I'm not sure what the interface should do. One idea I had was for the input interface to tell the game engine that (e.g.) the screen was clicked, then to let the game engine decide what to do with that information (shoot a bullet, for example). Another idea I had was for the input interface, having caught the mouse click, to tell the game engine to shoot a bullet. Which method would be better for me to use?

    Read the article

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

    - by Tomislav Nakic-Alfirevic
    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 model or the presenter - 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 me is that java.util.Observer and java.util.Observable are not supported in GWT. This suggests that what I'm doing is not the recommended way to do it, as far as GWT is concerned, which leads me to my questions: what is the recommended way to implement MVP using GWT, specifically with the above goals in mind? How would you do it?

    Read the article

  • How to perform different operations within Observer's update() in Java?

    - by Nazgulled
    I just started playing with Observable, Observer and it's update() method and I can't understand what should I do when different actions call notifyObservers(). I mean, my Observable class has a few different methods that call setChanged() and notifyObservers() in the end. Depending on the called method, some part of the UI (Swing) needs to be updated. However, there is only one update() method implemented in the Observer class. I though of passing something to the notifyObservers() method and then I can check the argument on update() but it doesn't seem feel like a good way to do it. Even if it did, what should I pass? A string with a short description of the action/method? And int, like an action/method code? Something else? What's the best way to handle this situation?

    Read the article

  • Tab Sweep: Java EE 6 Scopes, Observer, SSL, Workshop, Virtual Server, JDBC Connection Validation

    - by arungupta
    Recent Tips and News on Java, Java EE 6, GlassFish & more : • How Java EE 6 Scopes Affect User Interactions (DevX.com) • Why is Java EE 6 better than Spring ? (Arun Gupta) • JavaEE Revisits Design Patterns: Observer (Murat Yener) • Getting started with Glassfish V3 and SSL (JavaDude) • Software stacks market share within Jelastic: March 2012 (Jelastic) • All aboard the Java EE 6 Love Boat! (Bert Ertman) • Full stack Java EE workshop (Kito Mann) • Create a virtual server from console in glassfish (Hector Guzman) • Glassfish – JDBC Connection Validation explained (Alexandru Ersenie) • Automatically setting the label of a component in JSF 2 (Arjan Tijms) • JSF2 + Primefaces3 + Spring3 & Hibernate4 Integration Project (Eren Avsarogullari) • THE EXECUTABLE FEEL OF JAX-RS 2.0 CLIENT (Adam Bien) Here are some tweets from this week ... web-app dtd(s) on http://t.co/4AN0057b R.I.P. using http://t.co/OTZrOEEr instead. Thank you Oracle! finally got GlassFish and Cassandra running embedded so I can unit test my app #jarhell #JavaEE6 + #NetBeans is really a pleasure to work with! Reading latest chapter in #Spring vs #JavaEE wars https://t.co/RqlGmBG9 (and yes, #JavaEE6 is better :P) @javarebel very easy install and very easy to use in combination with @netbeans and @glassfish. Save your time.

    Read the article

  • How you would you describe the Observer pattern in beginner language?

    - by Sheldon
    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 project need a better understanding of the pattern itself and perhaps an example to see what its use. I don't want to force this pattern into something just to submit, I need to understand the purpose and develop my methods accordingly so that it actually serves a good purpose. My text doesn't really go into it, just mentions it in one sentence. MSDN was hard for me to understand, as I'm a beginner on this, and it seems more of an advanced topic. How would you describe this Observer pattern and its uses in C# to a beginner? For an example, please keep code very simple so I can understand the purpose more than complex code snippets. I'm trying to use it effectively with some simple textbox string manipulations and using delegates for my assignment, so a pointer would help!

    Read the article

  • why Observable snapshot observer vector

    - by han14466
    In Observable's notifyObservers method, why does the coder use arrLocal = obs.toArray();? Why does not coder iterate vector directly? Thanks public void notifyObservers(Object arg) { Object[] arrLocal; synchronized (this) { /* We don't want the Observer doing callbacks into * arbitrary code while holding its own Monitor. * The code where we extract each Observable from * the Vector and store the state of the Observer * needs synchronization, but notifying observers * does not (should not). The worst result of any * potential race-condition here is that: * 1) a newly-added Observer will miss a * notification in progress * 2) a recently unregistered Observer will be * wrongly notified when it doesn't care */ if (!changed) return; arrLocal = obs.toArray(); clearChanged(); } for (int i = arrLocal.length-1; i>=0; i--) ((Observer)arrLocal[i]).update(this, arg); }

    Read the article

  • Design Patterns for Coordinating Change Event Listeners

    - by mkraken
    I've been working with the Observer pattern in JavaScript using various popular libraries for a number of years (YUI & jQuery). It's often that I need to observe a set of property value changes (e.g. respond only when 2 or more specific values change). Is there a elegant way to 'subscribe' the handler so that it is only called one time? Is there something I'm missing or doing wrong in my design?

    Read the article

1 2 3 4 5 6 7 8 9 10  | Next Page >