Say we have the first Object 'Controller', and it initializes another object named "Tasks" when passing "self" for reference. Object Tasks can now exchange messages and send messages to the supercontroller object. Is this correct for communication between objects? Is this usually done? I just started to really learn programming, so I wonder if everything is in order. Until that moment, I relied on delegates and notifications. Is this a good practice?
Example:
// Controller Object task = [[Task alloc] initWithController: self]; - (void) runMethod: (NSString *) incoming { NSLog(@"%@", incoming); } // Task Object - (id) initWithController: (Controller *) ctrlr { controllerPointer = ctrlr; [controllerPointer runMethod:@"hello"]; return self } // All this should print out "hello"
And are there other ways of communicating, interacting between objects?
(Controller ) (Task). Model-View-Controller (MVC), , , , , , , , , .
Controller
Task
. , , , ? Task ? , , .
Cocoa , : (KVO). . , NSNotificationCenter. , .
NSNotificationCenter
KVO . , Cocoa , . (KVO Cocoa Bindings, , , iPhone SDK)
: , - . , .
, , , , .
?
. .
GC, , , Task , , , , Controller Task .
: controllerPointer . Controller.
controllerPointer
, ?
, , , , . , Task , .
, , , Controller , Task.
[[Controller sharedInstance] runMethod:@"hello"];
, , .
, , , , . 100% .
#import <Foundation/Foundation.h> @protocol MMNotificationDelegate <NSObject> - (void)acquireForwardClass:(id)f_class; - (void)notifyForwardClass:(NSDictionary*)dict; @end
, MMNotificationDelegate, , , , "" .
Source: https://habr.com/ru/post/1709744/More articles:How to implement openid support with classic asp? - iisIntroducing the Administration of Deeply Nested Resources - user-interfaceAdd border with mouse - jqueryThe best way to update user ratings without killing the server - optimizationHow to increase browser latency script - javascriptDesign-off-web application - .netThe problem with the width of the screen viewing the report in Mozila - htmlIPhone / iPod File System Speed โโ- profilingNull in Flex ComboBox - nullPodcast Creation Tutorial (in PHP) - xmlAll Articles