I'm building an app with, for the purposes of this question, three custom classes: AppDelegate, ListWindowController and ViewOptionsWindowController. AppDelegate keeps retains properties of the single instances of ListWindowController and ViewOptionsWindowController.
When the user selects a particular menu item, an action in AppDelegate is executed that instantiates the ViewOptionsWindowController. Changes made in this controller's window need to be reflected in ListWindowController's window (either adding or removing a column from the window's table view).
So, I've defined a protocol, ViewOptionsChanged, which has two required methods, -addColumn and -removeColumn (with parameters to indicate what to add or remove). I've indicated that ListViewController conforms to this protocol, and when instantiating ViewOptionsWindowController am passing AppDelegate's instance of ListViewController. The declaration of ViewOptionsWindowController's init method is:
- (id)initWithListController:(id <ViewOptionsChanged>)listController;
so that the only facts that ViewOptionsWindowController knows about the listController parameter is that it conforms to this protocol.
So, my question is, is this the proper use of Objective-C protocols? Or would some other design pattern be more appropriate?
's window, theListViewController` is also writing the changes to the user defaults. Honestly, this doesn't seem quite right, it seems like this result of the changes should happen in theAppDelegate. - Chuck