• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: KVG generic enough?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVG generic enough?


  • Subject: Re: KVG generic enough?
  • From: Graham Cox <email@hidden>
  • Date: Thu, 19 Jul 2012 13:09:40 +1000

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: KVC generic enough?
      • From: William Squires <email@hidden>
References: 
 >KVG generic enough? (From: William Squires <email@hidden>)
 >Re: KVG generic enough? (From: Graham Cox <email@hidden>)
 >Re: KVG generic enough? (From: Alex Zavatone <email@hidden>)
 >Re: KVG generic enough? (From: Graham Cox <email@hidden>)
 >Re: KVG generic enough? (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: Regex library recommendations ?
  • Next by Date: Re: KVG generic enough?
  • Previous by thread: Re: KVG generic enough?
  • Next by thread: Re: KVC generic enough?
  • Index(es):
    • Date
    • Thread