Re: only defined for abstract class
Re: only defined for abstract class
- Subject: Re: only defined for abstract class
- From: Francis Derive <email@hidden>
- Date: Fri, 7 Oct 2005 20:52:45 +0200
On Oct 7, 2005, at 1:37 AM, Kay Roepke wrote:
Francis, the inherited methods count -and -objectAtIndex: are
considered abstract. The thing is that Objective-C actually doesn't
have
the language equivalent of "abstract methods" as e.g. Java has. (In
other words, there's no compiler keyword 'abstract', it's simply not
a language feature.)
To still be able to make methods abstract an force the subclasser
to implement them, typically an exception is raised, or a message
doesNotImplement is sent (This stems from Smalltalk, which also has
no abstract keyword.).
Enough history: NSArray and NSMutableArray are two publicly visible
classes of the class cluster "Arrays". They provide all
the basic methods needed for an array. They do their work in terms
of their respective "primitive methods".
For NSArray those are -count and -objectAtIndex:.
So when you make a custom subclass of NSArray, you have to provide
those to methods in your subclass. You cannot call the superclass's
(NSArray's)
methods, because those just raise the exception all over again. In
this case overriding really means that: You completely replace the
"placeholder"
methods of your superclass.
Hope that helps :-) (Although this was just the paraphrase of the
docs...)
Regards,
Kay
A definitive guide - as is your post - to Obj-C subclassing does
help.
Somehow, there is no more to add, I am just thinking that I had
too much in mind the idea of inheritance that blurred my mind in this
special case of defining a (true) subclass.
Many thanks to all of you who have helped me here : Kay, m,
Mark, glen, Greg, Nick and Pontus.
Now we go ahead ! Cheers.
Francis.
_______________________________________________
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