Skip navigation.
 
mlRe: A Question of Style
FROM : Daniel Jalkut
DATE : Wed Aug 09 02:30:17 2006

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_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>-
> sweater.com
>
> This email sent to <email_removed>

Related mailsAuthorDate
mlA Question of Style Andrew Satori Aug 8, 03:40
mlRe: A Question of Style Daniel Jalkut Aug 9, 02:30