Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier-To-Understand Pattern #8

Open
idibidiart opened this issue Nov 9, 2015 · 1 comment
Open

Easier-To-Understand Pattern #8

idibidiart opened this issue Nov 9, 2015 · 1 comment

Comments

@idibidiart
Copy link

The use of the delegate pattern was a little confusing to me, so I ended up doing this:

//
//  Coordinator.h
//  RNEmbeddedAppExample
//

#import <Foundation/Foundation.h>
#import "RCTBridgeModule.h"
#import "SingleFlowViewController.h"

@interface SomeCoordinator : NSObject <RCTBridgeModule>

@property (nonatomic, assign) SingleFlowViewController *myViewController;

@end

And in ViewController.m

...
 [delegate.bridge.modules[@"SomeCoordinator"] setMyViewController:self];
...

For those of us new to Objective-C I think having the bridge on app delegate and then having to do setDelegate in that line in the implementation causes some confusion, semantically speaking.

Does this make any sense to you?

@dsibiski
Copy link
Owner

dsibiski commented Nov 9, 2015

@idibidiart: Yes, this makes sense, and is how I originally did it. However, I avoided this because here the coordinator has to specifically know which ViewController will be using it. You need to explicitly import the .h file, this couples these 2 classes together and can make things harder to change.

The delegate pattern allows any class to be able to use it as long as it implements the proper delegate methods. This keep things cleaner albeit perhaps a bit more confusing to those new to this pattern.

However, I do think that sometimes a coordinator perhaps should be coupled to a specific ViewController. I think it depends on your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants