Re: Obj-C question: protocol usage and inheritance
Re: Obj-C question: protocol usage and inheritance
- Subject: Re: Obj-C question: protocol usage and inheritance
- From: Normand Rivard <email@hidden>
- Date: Mon, 16 Sep 2002 23:52:21 -0400
According to
http://www.toodarkpark.org/computers/objc/moreobjc.html#787
(look for "Conforming to a Protocol"), "A class is said to conform to a
formal protocol if it adopts the protocol or inherits from a class that
adopts it. " This could mean that MySuperClass should also conform to
the protocol MyClassType to shut up the warnings. The problem is that in
general, it doesn't make sense (although it might in my specific case).
If someone from Apple from the compiler group can reply to this, I would
appreciate. My opinion is that a class should be said to conform to a
formal protocol if it adopts the protocol **by implementation or
inheritance** or inherits from a class that adopts it. I don't think it
would break any existing code if the compiler could be changed (fixed?)
to support that definition. Did I mention that even if I have warnings,
this code works perfectly well at run time?
The example I gave in my original question was not innocent. The
"modern" way of doing polymorphism often implies the usage of protocols
to type the polymorph classes from the exterior point of view and to use
an abstract class only as a container for common code. This frees the
designer from the tyranny of class hierachy: the client classes of my
class are not aware of my own hierarchy, therefore I can change it as I
wish if it makes sense. I use to do that often in C++ and Java (but not
in Smalltalk due to lack of protocols). It's very regrettable that Obj-C
does has protocols but gives warnings when I use them for polymorphism...
Any opinion on this?
Thanks
On Dimanche, septembre 15, 2002, at 02:07 , Nat! wrote:
The problem is that the compiler gives me warning because name and
setName are not implemented in MyClass (which is true: these methods
are inherited from MySuperClass). I thought the compiler would notice
that MyClass has access to these methods by inheritance.
I would have thought so too. I am not sure why this isn't the case. The
behaviour has been there the last 5 years at least and it's very
inconvenient.
How do you people usually deal with this? Do you re-define inherited
methods in sub-classes (yuck)? Are you even using protocol for
polymorphism?
Dont' laugh:
#warning (nat) ignore next two warnings because of compiler lameness
But mostly I have given up on protocols altogether.
Ciao
Nat!
Jedenfalls sind zehn Fehlstarts hintereinander [E. Fuchs]
ein sehr interessanter Beweis
fuer unsere Theorie
von der natuerlichen Ueberlegenheit des Dezimalsystems
_______________________________________________
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.
____________________________________________________________
"What you do instead of your real work *is* your real work."
- Roger Ebert
____________________________________________________________
_______________________________________________
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.