• 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: Function calling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function calling


  • Subject: Re: Function calling
  • From: Ondra Cada <email@hidden>
  • Date: Thu, 26 May 2005 03:23:18 +0200

Thomas,

On 26.5.2005, at 2:56, Thomas Davie wrote:

Quite agree - the part I was disputing was ``The object knows. That's called [...] "polymorphism".''

The part was completely right. What is polymorphism?

Polymorphism in fact means that you can send the same message to different objects, and they would behave accordingly. With strong typing, you just limit "different objects" to subclasses of some class, or to implementers of some protocol. (Or, in other langauges, to other similar primitives, but I thought we are discussing ObjC here, are we not?)

For example, in a plain function

int sum(id o) {
int sum=0;
for (NSEnumerator *en=[a objectEnumerator];o=[en nextObject];) sum +=[o intValue];
return sum;
}


could we perhaps benefit from strong typing, having the compiler to check that the argument is an NSArray and its items are NSNumnbers?

Nope, we could not -- actually, the very opposite: it would *cripple* the very idea of polymorphism. The way it is written now it would work all right with a set containing NSStrings, or, with a few simple categories, with, say, an NSImage and its NSImageReps or with an NSDocument and its NSWindowControllers -- or, truly, with *whatever*.

That is polymorphism at its best: the fact we can send *any* object messages "objectEnumerator" or "intValue" and presume it would behave accordingly (which may also mean "reports and error": that's definitely an appropriate reaction in case the object cannot support the appropriate service). The strong typing just *limits* polymorphism, never ever helps it.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Function calling
      • From: Bob Ippolito <email@hidden>
    • Re: Function calling
      • From: Thomas Davie <email@hidden>
References: 
 >Function calling (From: "Theodore H. Smith" <email@hidden>)
 >Re: Function calling (From: Ondra Cada <email@hidden>)
 >Re: Function calling (From: Thomas Davie <email@hidden>)
 >Re: Function calling (From: Bob Ippolito <email@hidden>)
 >Re: Function calling (From: Thomas Davie <email@hidden>)

  • Prev by Date: Re: Function calling
  • Next by Date: Re: Function calling
  • Previous by thread: Re: Function calling
  • Next by thread: Re: Function calling
  • Index(es):
    • Date
    • Thread