Polimorfisno (Vol. II)

Dunque.

Sul libro Programming in Objective C 2.0 di Stephen G Kochan (ISBN 978-0-321-56615-7), Addison Wesley, si dice che:

Chapter 9
Polymorphism, Dynamic Typing, and Dynamic Binding
(…)
Polimorphism enables programs to be developed so that objects from different classes can define methods that share the same name.

Che fa il paio con questo: http://edue.wordpress.com/2010/02/07/polimorfisno/

Ora, sarà che penso troppo Java ma continuo a ritenere questa definizione una tautologia rispetto al concetto di classe, oggetto e metodo, oppure una sonora vaccata.

Io il polimorfismo lo vedrei piuttosto così:


//
// ClassC.h
//

#import
#import "ClassA.h"

@interface ClassC : ClassA

- (void) printVar: (char*) s;
- (void) printVar: (char*) s : (char*) t;
@end

//
// ClassC.m
//

#import "ClassC.h"

@implementation ClassC

- (void) printVar: (char*) s
{
printf ("%s: %i\r", s, x);
}
- (void) printVar: (char*) s: (char*) t
{
printf ("%s di %s: %i\n", s, t, x);
}

@end

Lieto di essere smentito, motivatamente.

Polimorfisno

Da Object-Oriented Programming with Objective-C © Apple Inc. del 2008-11-19.

Overloading: The terms “polymorphism” and “argument overloading” refer basically to the same thing, but from slightly different points of view. Polymorphism takes a pluralistic point of view and notes that several classes can each have a method with the same name. Argument overloading takes the point of the view of the method name and notes that it can have different effects depending on the arguments passed to it. Operator overloading is similar. It refers to the ability to turn operators of the language (such as == and + in C) into methods that can be assigned particular meanings for particular kinds of objects. Objective-C implements polymorphism of method names, but not argument or operator overloading.

Forse sono troppo legato a Java, e il fatto che adesso sia in mano a Oracle mi fa cercare delle alternative anche di nicchia in maniera irrazionale, ma se questo è il polimorfismo dell’Objective-C…

R 20110111 1937