Re: A Question of Style
Re: A Question of Style
- Subject: Re: A Question of Style
- From: Daniel Jalkut <email@hidden>
- Date: Tue, 8 Aug 2006 20:30:17 -0400
Hi Andrew. It basically looks OK to me but I do think you are
overcomplicating things.
Your use of the term "controller" is a little bit confusing because
it's not clear whether you mean an NSWindowController or just some
object acting as a "controller layer object," serving as the window's
delegate.
I I were you I'd simplify the class by eliminating the
"withController" and "performOnComplete" parameters to
runModalForWindow. Instead, just make it clear in the header file
that parentWindow's delegate, if it exists and responds to a
particular well-defined method. You're really not gaining anything
by having the "flexibility" of providing a method of whatever name
you choose.
I would also change the name of the class to better reflect what it
does. How about "EXLoginController" ? EXSomeLogin doesn't mean much
to me. Then you could make it very clear what the caller's options
are by adding something like this to header file:
// The parent window's delegate may implement this method to be
notified of completion
@interface NSObject (EXLoginController)
- (void) exLoginCompletedForController:(EXLoginController*)
theController;
@end
I'm also a little bit confused as to why a method called
"runModalforWindow" would need a "completion" callback, because I
would expect it to block until complete. If the point of this class
is to display the window-modal dialog and then let the app continue
operating, then I would name the method something like
"beginModalLoginForWindow:".
Hope this helps,
Daniel
On Aug 7, 2006, at 9:40 PM, Andrew Satori wrote:
So I've got this framework and it works, but I've decided to clean
it up and make it publicly available, there is however a segment of
code that I question if it's really done in Cocoa Style, and I'm
looking for best practices from the more experienced Cocoa Devs.
I have a class in the framework that encapsulates and displays a
login panel modal for a parent window.
At the moment, it using a method that takes an id for a controller
for the parent window controller, an NSWindow * for the parent
window and a selector for the selector to be invoked upon
completion so for example:
@interface EXSomeLogin : NSObject {
...
SEL onCompleteSelector;
id parentController;
}
-(id)runModalForWindow:(NSWindow *)parentWindow
withController:(id)controller
performOnComplete:(SEL)completeSelector;
-(IBAction)onDialogComplete:(id)sender;
@end
In the runModalForWindow function, I set the members as passed in:
onCompleteSelector = completeSelector;
parentController = controller;
and then do the usual modal display for the panel (loading the nib
etc).
When the onDialogComplete happens, I then do my work inside the
framework (and set the Class members accordingly) then I call back
to the parentController using the selector passed in:
[parentController performSelector:onCompleteSelector
withObject:self afterDelay:0.0];
My concern is style. Is this a normal usage pattern or am I over
complicating something ?
Your thoughts appreciated!
D.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
sweater.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden