Let's say I have three custom objects in Objective-C: ClassA: UIViewController <ClassBDelegate>
, ClassB: NSObject <ClassCDelegate>
, ClassC: NSObject
. ClassA is a subclass of UIViewController that will display an activity indicator until a certain network event happens in ClassC. ClassB has a ClassC, among other classes, and is responsible for relaying events from ClassC to ClassA. ClassA has a ClassB, and ClassB has a ClassC, there is no direct connection from ClassA to ClassC.
Now lets say once the particular network event happens in ClassC, that ClassC will fire off - (void)someAction;
. ClassB conforms to the ClassC delegate protocol, and its - (void)classC:(ClassC *)classC didPerformSomeAction;
method is called. In turn, ClassB fires off -(void)thisOtherAction;
, and since ClassA conforms to the ClassB delegate protocol, its -(void)classB:(ClassB *)classB didPerformThisOtherAction;
gets called, which effectively retrieves the network event from ClassC.
My question is, is this bad practice, and if so, is there an easier way to bridge the gap between ClassA and ClassC? I am hesitant to use a NSNotification because I think delegate protocols are more elegant. However, this seems sort of like a relay race to me. I would appreciate any information about popular conventions in a scenario such as this.