FROM : Quincey Morris
DATE : Tue Mar 11 23:49:34 2008
On Mar 11, 2008, at 14:09, Stuart Malin wrote:
> My rationale for departing from the canonical approach is because
> then I get a bit of extra type checking at compile time.
Personally I prefer the factory method approach, a la [NSArray array]
etc:
In your header file:
+ (XMPPStream*) xmppStreamWithDelegate: (id)initialDelegate;
In the implementation:
- (id) initWithDelegate:(id)initialDelegate {...}
+ (XMPPStream*) xmppStreamWithDelegate: (id)initialDelegate {return
[[[XMPPStream alloc] initWithDelegate:initialDelegate] autorelease];}
Usage:
someStream = [XMPPStream xmppStreamWithDelegate:delegate];
This (a) gives you the compile time type check, (b) saves a few
keystrokes of clutter wherever you actually create one of these, (c)
forces creation of the object to use a designated initializer without
chance of mistakes, and (d) allows you to use the proper (id) return
type on your initializers.
DATE : Tue Mar 11 23:49:34 2008
On Mar 11, 2008, at 14:09, Stuart Malin wrote:
> My rationale for departing from the canonical approach is because
> then I get a bit of extra type checking at compile time.
Personally I prefer the factory method approach, a la [NSArray array]
etc:
In your header file:
+ (XMPPStream*) xmppStreamWithDelegate: (id)initialDelegate;
In the implementation:
- (id) initWithDelegate:(id)initialDelegate {...}
+ (XMPPStream*) xmppStreamWithDelegate: (id)initialDelegate {return
[[[XMPPStream alloc] initWithDelegate:initialDelegate] autorelease];}
Usage:
someStream = [XMPPStream xmppStreamWithDelegate:delegate];
This (a) gives you the compile time type check, (b) saves a few
keystrokes of clutter wherever you actually create one of these, (c)
forces creation of the object to use a designated initializer without
chance of mistakes, and (d) allows you to use the proper (id) return
type on your initializers.






Cocoa mail archive

