Search Results

Search found 577 results on 24 pages for 'delegates'.

Page 4/24 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • 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

  • MVC and delegation

    - by timjver
    I am a beginning iOS programmer and use the Model-View-Controller model as a design pattern: my model doesn't know anything about my view (in order to make it compatible with any view), my view doesn't know anything about my model so they interact via my controller. A very usual way for a view to interact with the controller is through delegation: when the user interacts with the app, my view will notify my controller, which can call some methods of my model and update my view, if necessary. However, would it make sense to also make my controller the delegate of my model? I'm not convinced this is the way to go. It could be handy for my model to notify my controller of some process being finished, for example, or to ask for extra input of the user if it doesn't have enough information to complete the task. The downside of this, though, is that my controller would be the delegate for both my controller and my model, so there wouldn't be really a proper way to notify my model of changes in my view, and vice versa. (correct me if I'm wrong.) Conclusion: I don't really think it's a good idea to to have my controller to be the delegate of my model, but just being the delegate of my view would be fine. Is this the way most MVC models handle? Or is there a way to have the controller be the delegate of both the controller and the model, with proper communication between them? Like I said, I'm a beginner, so I want to do such stuff the right way immediately, rather than spending loads of hours on models that won't work anyway. :)

    Read the article

  • How can i mock or test my deferred execution functionality?

    - by cottsak
    I have what could be seen as a bizarre hybrid of IQueryable<T> and IList<T> collections of domain objects passed up my application stack. I'm trying to maintain as much of the 'late querying' or 'lazy loading' as possible. I do this in two ways: By using a LinqToSql data layer and passing IQueryable<T>s through by repositories and to my app layer. Then after my app layer passing IList<T>s but where certain elements in the object/aggregate graph are 'chained' with delegates so as to defer their loading. Sometimes even the delegate contents rely on IQueryable<T> sources and the DataContext are injected. This works for me so far. What is blindingly difficult is proving that this design actually works. Ie. If i defeat the 'lazy' part somewhere and my execution happens early then the whole thing is a waste of time. I'd like to be able to TDD this somehow. I don't know a lot about delegates or thread safety as it applies to delegates acting on the same source. I'd like to be able to mock the DataContext and somehow trace both methods of deferring (IQueryable<T>'s SQL and the delegates) the loading so that i can have tests that prove that both functions are working at different levels/layers of the app/stack. As it's crucial that the deferring works for the design to be of any value, i'd like to see tests fail when i break the design at a given level (separate from the live implementation). Is this possible?

    Read the article

  • $.(ajax) wrapper for Jquery - passing parameters to delegates

    - by gnomixa
    I use $.(ajax) function extensively in my app to call ASP.net web services. I would like to write a wrapper in order to centralize all the ajax calls. I found few simple solutions, but none address an issue of passing parameters to delegates, for example, if i have: $.ajax({ type: "POST", url: "http://localhost/TemplateWebService/TemplateWebService/Service.asmx/GetFoobar", data: jsonText, contentType: "application/json; charset=utf-8", dataType: "json", success: function(response) { var results = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d; OnSuccess(results, someOtherParam1, someOtherParam2); }, error: function(xhr, status, error) { OnError(); } }); The wrapper to this call would have to have the way to pass someOtherParam1, someOtherParam2 to the OnSuccess delegate...Aside from packing the variables into a generic array, I can't think of other solutions. How did you guys address this issue?

    Read the article

  • When to release a class with delegates

    - by Stefan Mayr
    A quick question to delegates. Lets say, CLASSA has a delegate defined: @protocol MyDelegate -(void) didFinishUploading; @end In CLASSB I create an instance of CLASS A -(void) doPost { CLASSA *uploader = [[CLASSA alloc] init]; uploader.delegate = self; // this means CLASSB has to implement the delegate uploader.post; } and also in CLASSB: -(void)didFinishUploding { } So when do I have to release the uploader? Because when I release it in doPost, it is not valid anymore in didFinishUploading. Thanks

    Read the article

  • Delegates vs. events in Cocoa

    - by aaronstacy
    I'm writing my first iPhone app, and I've been exploring the design patterns in Cocoa and Objective-C. I come from a background of client-side web development, so I'm trying to wrap my head around delegates. Specifically, I don't see why delegate objects are needed instead of event handlers. For instance, when the user presses a button, it is handled with an event (UITouchUpInside), but when the user finishes inputting to a text box and closes it with the 'Done' button, the action is handled by calling a method on the text box's delegate (textFieldShouldReturn). Why use a delegate method instead of an event? I also notice this in the view controller with the viewDidLoad method. Why not just use events?

    Read the article

  • How to manage large amounts of delegates and usercallbacks in C# async http library

    - by Tyler
    I'm coding a .NET library in C# for communicating with XBMC via its JSON RPC interface using HTTP. I coded and released a preliminary version but everything is done synchronously. I then recoded the library to be asynchronous for my own purposes as I was/am building an XBMC remote for WP7. I now want to release the new async library but want to make sure it's nice and tidy before I do. Due to the async nature a user initiates a request, supplies a callback method that matches my delegate and then handles the response once it's been received. The problem I have is that within the library I track a RequestState object for the lifetime of the request, it contains the http request/response as well as the user callback etc. as member variables, this would be fine if only one type of object was coming back but depending on what the user calls they may be returned a list of songs or a list of movies etc. My implementation at the moment uses a single delegate ResponseDataRecieved which has a single parameter which is a simple Object - As this has only be used by me I know which methods return what and when I handle the response I cast said object to the type I know it really is - List, List etc. A third party shouldn't have to do this though - The delegate signature should contain the correct type of object. So then I need a delegate for every type of response data that can be returned to the third party - The specific problem is, how do I handle this gracefully internally - Do I have a bunch of different RequestState objects that each have a different member variable for the different delegates? That doesn't "feel" right. I just don't know how to do this gracefully and cleanly.

    Read the article

  • The Main Purpose of Events in C#

    - by Tarik
    I've been examining one of my c# books and I just saw a sentence about Events in C#:  The main purpose of events is to prevent subscribers from interfering with each other. Whatever it means, yeah actually events are working pretty much like delegates. I've been wondering why I should use events instead of delegates. So is there any one who can explain the bold part? Thanks in advance.

    Read the article

  • C# Chain-of-responsibility with delegates

    - by nettguy
    For my understanding purpose i have implemented Chain-Of-Responsibility pattern. //Abstract Base Type public abstract class CustomerServiceDesk { protected CustomerServiceDesk _nextHandler; public abstract void ServeCustomers(Customer _customer); public void SetupHadler(CustomerServiceDesk _nextHandler) { this._nextHandler = _nextHandler; } } public class FrontLineServiceDesk:CustomerServiceDesk { public override void ServeCustomers(Customer _customer) { if (_customer.ComplaintType == ComplaintType.General) { Console.WriteLine(_customer.Name + " Complaints are registered ; will be served soon by FrontLine Help Desk.."); } else { Console.WriteLine(_customer.Name + " is redirected to Critical Help Desk"); _nextHandler.ServeCustomers(_customer); } } } public class CriticalIssueServiceDesk:CustomerServiceDesk { public override void ServeCustomers(Customer _customer) { if (_customer.ComplaintType == ComplaintType.Critical) { Console.WriteLine(_customer.Name + "Complaints are registered ; will be served soon by Critical Help Desk"); } else if (_customer.ComplaintType == ComplaintType.Legal) { Console.WriteLine(_customer.Name + "is redirected to Legal Help Desk"); _nextHandler.ServeCustomers(_customer); } } } public class LegalissueServiceDesk :CustomerServiceDesk { public override void ServeCustomers(Customer _customer) { if (_customer.ComplaintType == ComplaintType.Legal) { Console.WriteLine(_customer.Name + "Complaints are registered ; will be served soon by legal help desk"); } } } public class Customer { public string Name { get; set; } public ComplaintType ComplaintType { get; set; } } public enum ComplaintType { General, Critical, Legal } void Main() { CustomerServiceDesk _frontLineDesk = new FrontLineServiceDesk(); CustomerServiceDesk _criticalSupportDesk = new CriticalIssueServiceDesk(); CustomerServiceDesk _legalSupportDesk = new LegalissueServiceDesk(); _frontLineDesk.SetupHadler(_criticalSupportDesk); _criticalSupportDesk.SetupHadler(_legalSupportDesk); Customer _customer1 = new Customer(); _customer1.Name = "Microsoft"; _customer1.ComplaintType = ComplaintType.General; Customer _customer2 = new Customer(); _customer2.Name = "SunSystems"; _customer2.ComplaintType = ComplaintType.Critical; Customer _customer3 = new Customer(); _customer3.Name = "HP"; _customer3.ComplaintType = ComplaintType.Legal; _frontLineDesk.ServeCustomers(_customer1); _frontLineDesk.ServeCustomers(_customer2); _frontLineDesk.ServeCustomers(_customer3); } Question Without breaking the chain-of-responsibility ,how can i apply delegates and events to rewrite the code?

    Read the article

  • OO model for nsxmlparser when delegate is not self

    - by richard
    Hi, I am struggling with the correct design for the delegates of nsxmlparser. In order to build my table of Foos, I need to make two types of webservice calls; one for the whole table and one for each row. It's essentially a master-query then detail-query, except the master-query-result-xml doesn't return enough information so i then need to query the detail for each row. I'm not dealing with enormous amounts of data. Anyway - previously I've just used NSXMLParser *parser = [[NSXMLParser alloc]init]; [parser setDelegate:self]; [parser parse]; and implemented all the appropriate delegate methods in whatever class i'm in. In attempt at cleanliness, I've now created two separate delegate classes and done something like: NSXMLParser *xp = [[NSXMLParser alloc]init]; MyMasterXMLParserDelegate *masterParserDelegate = [[MyMasterXMLParser]alloc]init]; [xp setDelegate:masterParserDelegate]; [xp parse]; In addition to being cleaner (in my opinion, at least), it also means each of the -parser:didStartElement implementations don't spend most of the time trying to figure out which xml they're parsing. So now the real crux of the problem. Before i split out the delegates, i had in the main class that was also implementing the delegate methods, a class-level NSMutableArray that I would just put my objects-created-from-xml in when -parser:didEndElement found the 'end' of each record. Now the delegates are in separate classes, I can't figure out how to have the -parser:didEndElement in the 'detail' delegate class "return" the created object to the calling class. At least, not in a clean OO way. I'm sure i could do it with all sorts of nasty class methods. Does the question make sense? Thanks.

    Read the article

  • Does "delegate" mean a type or an object?

    - by Michal Czardybon
    Reading from MSDN: "A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method." Does then "delegate" mean a type or an object?! ...It cannot be both. It seems to me that the single word is used in two different meanings: a type containing a reference to a method of some specified signature, an object of that type, which can be actually called like a method. I would prefer a more precise vocabulary and use "delegate type" for the first case. I have been recently reading a lot about events and delegates and that ambiguity was making me confused many times. Some other uses of "delegate" word in MSDN in the first meaning: "Custom event delegates are needed only when an event generates event data" "A delegate declaration defines a class that is derived from the class System.Delegate" Some other uses of "delegate" word in MSDN in the second meaning: "specify a delegate that will be called upon the occurrence of some event" "Delegates are objects that refer to methods. They are sometimes described as type-safe function pointers" What do you think? Why did people from Microsoft introduced this ambiguity? Am I the only person to have conceptual problems with different notions being referenced with the same word.

    Read the article

  • Setting ViewController delegates in iPhone runtime

    - by Stein Rune Risa
    I am writing an iPhone application and needed to use the address book functionality. For this to work, it is necessary to specify a ABPeoplePickerNavigationControllerDelegate on the ViewController. The problem is that I am creating all fields and buttons dynamically runtime, and thus does not have any custom ViewController - using only UIViewController class. My question is then - how can I specify the delegate runtime without having to create a ViewController class just for this purpose.

    Read the article

  • Customising event delegates in the jQuery validation plug-in

    - by Russell
    I am currently setting up the jQuery validation plug-in for use in our project. By default, there are some events automatically set up for handling. I.e. focus in/out, key up events on all inputs fire validation. I want it to only fire when the submit button is clicked. This functionality seems to be in-built into the plug-in, which is making it difficult to do this (without modifying the plug-in code, Not What I Want To Do). I have found the eventDelegate function calls in the plugin code prototype method: $(this.currentForm) .validateDelegate(":text, :password, :file, select, textarea", "focusin focusout keyup", delegate) .validateDelegate(":radio, :checkbox, select, option", "click", delegate); When I remove these lines from the plug-in I get my result, however I would much rather do something Outside the plug-in to achieve this. Can anybody please help me? If you need any more details, please let me know. I have searched google with little success. Thanks

    Read the article

  • Asynchronous Delegates Vs Thread/ThreadPool?

    - by claws
    Hello, I need to execute 3 parallel tasks and after completion of each task they should call the same function which prints out the results. I don't understand in .net why we have Asychronous calling (delegate.BeginInvoke() & delegate.EndInvoke()) as well as Thread class? I'm little confused which one to use when? Now in this particular case, what should I use Asychronous calling or Thread class? I'm using C#.

    Read the article

  • Contravariant Delegates Value Types

    - by ChloeRadshaw
    Can anyone shed light on why contravariance does not work with C# value types? The below does not work private delegate Asset AssetDelegate(int m); internal string DoMe() { AssetDelegate aw = new AssetDelegate(DelegateMethod); aw(32); return "Class1"; } private static House DelegateMethod(object m) { return null; }

    Read the article

  • Registering a delegate function with an ISO C++ callback (on mono)

    - by Stick it to THE MAN
    I am thinking of wrapping ISO C++ code in C# class. The only problem so far is how to deal with the C++ callbacks. In .Net languages (C# and Vb.Net), I believe the callback equivalent. Sticking with C# for now, can anyone recommend a way that I can register the C# delegate functions with my ISO C++ code. The ISO C++ code is a notification library, and I want to be able to "push" the notifications to the mono framework (i.e. C# delegates in this case). My underlying assumption is that the mechanism/steps to implement this would be the same for the .Net languages - I'll just have to code the actual delegates in the .Net language of choice - is that assumption correct? Last but not the least, is the question of thread saftey. The underlying ISO C++ code that I am exposing to .Net (mono to be more specific), is both re-ntrant and thread safe - do I have to do anything "extra" to call .Net delegate from my ISO C++ code?

    Read the article

  • Delegates does not work properly

    - by Warrior
    I am new to iPhone development. I am converting the date to the desired format and set it to the delegate and get its value in the another view. The session restarts when I tried to get the value from delegate. If I set the original date and not the formatted date in the set delegate, then i able to get the value in the another view. If I also give any static string value, then also I am able to the static string value back. Only the formatted date which is string is set then the session restarts. If i print and check the value of the formatted date it prints the correct formatted date only.Please help me out.Here is my code for date conversion NSString *dateval=[[stories objectAtIndex: storyIndex] objectForKey:@"date"]; NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init]; [inputFormatter setDateFormat:@"EEE, MMM dd, yyyy"]; NSDate *inputDate = [inputFormatter dateFromString:dateval]; NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; [outputFormatter setDateFormat:@"MMMM dd"]; NSString *outputDate = [outputFormatter stringFromDate:inputDate]; AppDelegate *delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate]; [delegate setCurrentDates:outputDate]; EDIT: This is displayed in console inside view did load [Session started at 2010-04-21 19:12:53 +0530.] GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 4216. (gdb) In another view - (void)viewDidLoad { NSLog(@"inside view did load"); AppDelegate *delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate]; NSString *titleValue=[delegate getCurrentDates]; self.navigationItem.title =titleValue ; } The get does not work properly.It works fine if i give any static string or the "dateval". Thanks.

    Read the article

  • ThreadExceptionEventHandler and invoking delegates

    - by QmunkE
    If I assign a ThreadExceptionEventHandler to Application.ThreadException, why when I invoke a delegate method using a control on the main application thread are any exceptions thrown by that delegate not triggering the event handler? i.e. static void Main() { ... Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); Application.Run(new Form1()); } static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { Console.Error.Write("A thread exception occurred!"); } ... private void Form1_Load(object sender, EventArgs e) { Thread syncThread = new Thread(new ThreadStart(this.ThrowException)); syncThread.Start(); } private void ThrowException() { button1.Invoke(new MethodInvoker(delegate { // Not handled by ThreadExceptionEventHandler? throw new Exception(); })); } The context on this is that I have a background thread started from a form which is throwing an unhandled exception which terminates the application. I know this thread is going to be unreliable since it is network connectivity reliant and so subject to being terminated at any point, but I'm just interested as to why this scenario doesn't play out as I expect?

    Read the article

  • UITableViewController setting delegates and datasource

    - by the_great_monkey
    Hi iOS gurus, I'm a little bit confused about UITableViewController... As far as I concern they are typically the delegate and datasource of the UITableView (although it can be made such that they are different). However in some cases, like when embedding a UITableViewController in a UITabBarViewController in Interface Builder, we initiate our table view controller in IB. Therefore in my understanding, the default initialiser is being called. But in this case, I have this piece of code: @interface Settings : UITableViewController { } And in the IB I see that the delegate and datasource of the UITableView is hooked up to this class. My question is, why is it that we don't need to explicitly say that it is following: @interface Settings : UITableViewController <UITableViewDelegate, UITableViewDataSource> { } And in the .m file: - (void)viewDidLoad { [super viewDidLoad]; [tableView setDelegate:self]; [tableView setDataSource:self]; } I have indeed stumbled upon some cases where I have to explicitly code the above a few times to make something work. Although it is still a mystery for me as of why it is needed...

    Read the article

  • How do I change the background image of my iPhone app?

    - by alJaree
    Hello I have looked around and found some code which so called chooses an image from an array of image objects, but cant find an explanation. I would like to make my app have a background image and the user can select next and previous buttons to scroll through some full screen images, setting them as the background image as they scroll. I know how to do this in java, but cant seem to do it for this app. How or what code is linked to a next button to grab the next image in the array and reverse for the back button? Then that needs to be displayed obviously. I have used a layered architecture with a MVC style approach but cant seem to put it together with Objective-C. Would the buttons call the appropriate methods of the so called delegates, which the delegates handle fetching and returning the Images? Would the buttons use the returned images and actually handle the redrawing? I would really appreciate the help. Regards Jarryd

    Read the article

  • RoR model field without validators, has*, delegates, etc

    - by jackr
    How can I declare a field, in the Rails model, when it doesn't have any "has_" relations, or validations, or delegations? I just need to ensure its existence and column width in the schema. Currently, I have no mention of the field in the "schema section" of the model file, but it's referenced in various methods that use it, and this seems to work. However, depending on my exact creation workflow, the underlying database table may be created as t.binary "field_name", :limit => 32 or t.binary "field_name", :limit => 255 This is not a restriction on the value (any binary value is valid, even NULL), only on the table column declaration. As it happens, 32 is enough -- it never receives any larger value, it's only ever written to like this: self.field_name = SecureRandom.random_bytes(32)

    Read the article

  • Difference between two UIScrollView delegates

    - by Michael
    scrollViewDidEndScrollingAnimation and scrollViewDidEndDecelerating Looks like the last one is called when the bouncing effect is finished. But can't really understand what's the difference between first because they are called same time(well, decelerating called first).

    Read the article

  • How do I change the background image of my app?

    - by user356387
    Hello I have looked around and found some code which so called chooses an image from an array of image objects, but cant find an explanation. I would like to make my app have a background image and the user can select next and previous buttons to scroll through some full screen images, setting them as the background image as they scroll. I know how to do this in java, but cant seem to do it for this app. How or what code is linked to a next button to grab the next image in the array and reverse for the back button? Then that needs to be displayed obviously. I have used a layered architecture with a MVC style approach but cant seem to put it together with Objective-C. Would the buttons call the appropriate methods of the so called delegates, which the delegates handle fetching and returning the Images? Would the buttons use the returned images and actually handle the redrawing? I would really appreciate the help. Regards Jarryd

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >