Re: NSData object trouble with <16KB
Re: NSData object trouble with <16KB
- Subject: Re: NSData object trouble with <16KB
- From: Ondra Cada <email@hidden>
- Date: Fri, 23 Apr 2004 00:19:12 +0200
David,
On 23.4.2004, at 0:04, David Piasecki wrote:
>
Thanks. That makes more sense now. I had previously assumed (coming
>
from the C++/Java world) that alloc created a new object and init or
>
initFoo simply called different constructors.
In a sense it's exactly so, *but* the ObjC "constructors" (if we, for
the moment, decide to call init...'s so) are much more flexible than
the C++/Java ones since they
- are inherited, allowing so the charm of designated initializer;
- can replace the object by another one (that's what we bumped into);
- can report a problem returning nil (which is in a sense just a
special case of the previous item).
Incidentally, there's a price to pay for the flexibility: there's some
danger of a code which is called over an "uninitialized" object.
Luckily, in practice it happens very, very rarely, but especially if
designing new classes to be widely used by other programmers, you want
to consider the danger of
// beware, WRONG code
@implementation Foo
-init {
if (!(self=[super init])) return nil; // this is the proper paradigm
of initializing the superclass
[self foo];
return self;
}
-(void)foo { ... }
@end
@implementation Bar:Foo
-init {
if (!(self=[super init])) return nil;
SOME_LOCAL_INITIALIZATION
return self;
}
-(void)foo {
SOME_CODE_WHICH_FAILS_UNLESS_LOCAL_INITIZATION_WAS_DONE
}
@end
---
Ondra Hada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.