ios - Using cleaning delegate pattern -
i have protocol :
#import <foundation/foundation.h> @protocol storedisplayerdelegate <nsobject> -(void) changeactionforobjectwithid:(nsstring *)objectid ; @end
and have callass conforms precedent protocol storedisplayerdelegate
@interface shelfvc : uiviewcontroller :<storedisplayerdelegate> .... @implementation shelfvc ... - (void)viewdidload { ... downloadmanager *manager = [downloadmanager sharedinstance]; [manager setstoredisplayerdelegate:self]; .... } #pragma mark storedisplayerdelegate methods -(void) changeactionforobjectwithid:(nsstring *)objectid { ...... } @end
and in code ( in same class) calling delegate methods form me, example :
- (void)anothermethod{ [self changeactionforobjectwithid:nil]; }
my questions 1. : when object delegate other object, methods implemented delegate called other object ( witch have reference ) ? mean this, example in code have shown should methode changeactionforobjectwithid:
called download manager or can use in inernal of class :
- is doing cleaning or bad design of using delegate pattern ?
i hope clear.
in project have same situation different purpose. in opinion delegate method must called other object, because method.
if need action in delegate method, better create private method performing action , call delegate methods.
some example. instead of doing this:
- (void)anothermethod { [self changeactionforobjectwithid:nil]; } - (void)changeactionforobjectwithid:(nsstring *)objectid { < actions > }
i this:
- (void)privatemethod{ < actions > } - (void)anothermethod { [self privatemethod]; } - (void)changeactionforobjectwithid:(nsstring *)objectid { [self privatemethod]; }
why this? because have think delegate methods "extension" base object: if delete "changeactionforobjectwithid" (becuase, example, don't need delegate anymore after refactoring) code continue work.
Comments
Post a Comment