On 19/07/2012, at 1:33 AM, Alex Zavatone wrote:

> Ah, yes, when coding, of course.  For some reason, I was expecting that 
> during runtime/debugging, if you know the name of an object or you are 
> accessing a object your coworker wrote there was some concept that instantly 
> told you its class and makeup. 


Well, there is - you can use the runtime functions to delve into the class 
hierarchy of an object.

But that's not how you write code.

If you are using code a co-worker wrote then you use the documentation that the 
co-worker provided to make use of it. And by documentation I mean the headers - 
they are the "contract" which his code promises to abide by. If a property is 
declared to return a string and it doesn't, that's a bug, pure and simple. The 
same headers told you the names of the properties - how else would you know 
them? Property declarations link a name to a type. If every property were typed 
'id' however and you were expected to examine the type at runtime, then your 
co-worker should probably be pensioned off rather quickly. Where a type is 
returned as 'id', it means that any object can be returned, and that's a hint 
that your code should not need to care what it is, and so, if you find yourself 
needing to know, that could be a code smell that something's amiss in your 
approach.

Note that -isKindOfClass only tells you whether an object is a given class or a 
subclass of it, it returns a BOOL. So it's only there to confirm what you 
already expect, or to reject silly mistakes, like passing in the wrong kind of 
object to something that must have another kind.

If you do something like this:

NSString* theType = NSStringFromClass([someObject class]);

if([theType isEqualToString:@"classTypeA"])
{
        [self doStuffForClassAType:someObject];
}
else if( [theType isEqualToString:@"classTypeB"])
{
        [self doStuffForClassBType:someObject];

}
else if .....


then that's really violating the spirit and intention of object-oriented 
programming.


--Graham
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to