Re: Protocol implementation split between base and derived class
Re: Protocol implementation split between base and derived class
- Subject: Re: Protocol implementation split between base and derived class
- From: Scott Hancher <email@hidden>
- Date: Thu, 9 Dec 2004 11:34:37 -0800
This line
"A class is said to conform to a formal protocol if it (or a
superclass) implements the methods declared in the protocol."
seems quite unambiguous.
I suppose you could argue that
"A class is said to adopt a formal protocol if it agrees to implement
the methods the protocol declares."
means that the class and not its inherited classes must implement the
protocol methods, but that seems like a tenuous argument at best. When
calling a method on an object of a particular type, it's irrelevant
where that method is implemented in the object's inheritance chain; it
only matters that a class in the inheritance chain implements the
method.
I would argue that this is an error in the compiler, or at the very
least an error in the documentation.
Thanks for the response,
++Scott.
On Thursday, December 9, 2004, at 08:52 AM, Prachi Gauriar wrote:
On Dec 8, 2004, at 7:16 PM, Scott Hancher wrote:
Can anyone comment on why XCode is throwing a compiler warning
though? This seems like an error to me.
The language in the Objective-C spec is somewhat ambiguous, but my
interpretation of it is that the compiler is correct.
@interface MyClass: MySuperClass <MyProtocol>
...
@end
implies that MyClass *adopts* MyProtocol. From the spec: "A class
is said to adopt a formal protocol if it agrees to implement the
methods the protocol declares." This leads me to believe that the
class itself has to implement the methods in the protocol, i.e.
adoption cannot be inherited.
Conforming to a protocol isn't as strong. "A class is said to conform
to a formal protocol if it (or a superclass) implements the methods
declared in the protocol."
Finally, an incorporated protocol is what you used to solve your
problem, a protocol within another protocol:
@protocol MyProtocol <MyOtherProtocol>
...
@end
A class can adopt an incorporated protocol by either "implementing the
methods the protocol declares, or inheriting from a class that adopts
the protocol and implements the methods."
See
<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/
LanguageOverview/chapter_3_section_7.html> for more details.
-Prachi
_______________________________________________
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