Re: Future Objective-C changes
Re: Future Objective-C changes
- Subject: Re: Future Objective-C changes
- From: Prachi Gauriar <email@hidden>
- Date: Fri, 16 May 2003 02:06:18 -0500
On Friday, May 16, 2003, at 01:16 AM, David Cittadini wrote:
With regards to method overloading, I thought it may be useful to be
able to say:
-(int)doSomethingWithFoo:(Foo*)y;
-(int)doSomethingWithFoo:(int)y;
With method overloading the compiler could resolve most of the
parameter type issues without me having to create different method
names just because the parameter type is different.
Don't forget, unlike C++/Java, Objective C is weakly-typed. Because of
this, the need for method overloading is often unnecessary. You could
always do something like
- (int)doSomethingWithFoo:(id)foo
{
if ([foo isKindOfClass:[SomeClass class]]) {
[foo doThis];
} else if ([foo isKindOfClass:[SomeOtherClass class]]) {
[foo doThisInstead];
}
return anInt;
}
If you wrap an int or other C primitive in an Obj-C wrapper, like
NSNumber, you can do this pretty easily. Of course, if you have a
different number of arguments, your method name is different anyway.
As the number of args increases, this doesn't get too much worse,
though it is definitely more of a pain than in C++ or Java. You don't
detect this at compile time, but you avoid runtime problems too.
-Prachi
_______________________________________________
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.