discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help understanding subclassing issue


From: David Chisnall
Subject: Re: Need help understanding subclassing issue
Date: Fri, 20 Feb 2009 13:10:00 +0000

On 20 Feb 2009, at 04:35, Pierre Bernatchez wrote:

David Chisnall wrote:
On 19 Feb 2009, at 21:35, Pierre Bz wrote:
I wrote a simplified (trivial) subclass of NSDictionary
and it fails
This is expected. As the documentation says, NSDictionary is a class cluster. Concrete subclasses must implement these three primitive methods:

The documentation I was looking at indicated none of that.
Perhaps you could point me to the documentation you are reading.

I looked up NSDictionary in the GNUstep base class reference:
http://www.gnustep.org/resources/documentation/Developer/Base/Reference/Base.html

Anyway,  thanks for the clear answer, it was exactly what I needed.

Generally, I only use the GNUstep documentation for GNUstep-specific features. If you google for NSDictionary, this is the top hit:

http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html

Looking at this page, it actually doesn't mention the fact that NSDictionary is a class cluster explicitly either. The only hint given here (and in the OpenStep spec) is the section on primitive methods. Generally speaking, when a class has a set of methods described as `primitive' you should implement them yourself in any subclass.

You should probably explain why you are trying to subclass NSDictionary though. Most of the time, this is the wrong thing to do.

I wanted to write any subclass to see if I had the right idea
of how to do that.  I wanted to grasp how to subclass in
a way that both observes the GNUstep initxxxx convention and
is MAC compatible.

A lot of the Foundation classes follow this pattern. This includes NSValue, NSNumber, NSString, all of the collection classes, and so on. In general, subclassing is not encouraged for OpenStep programs.

It seems I picked the wrong class for the experiment.
I got no diagnostic message at all at first, only 'abort'.

The uncaught exception handler should have printed a diagnostic message before exiting. I'm not sure why it didn't for you.

Then with the exception handler I got the message about 'count'.
All rather obscure until you know the solution.

This line seems quite self-explanatory:

REASON:subclass OGBanner(instance) should override count

The OGBanner class must override the instance method `count'.

Next time I'll leap to the cluster/abstract class issue in a flash,
and seek better docs.

My advice with regard to documentation is to stick to using the Apple docs and if you find something that doesn't work on GNUstep either implement it and send a patch, or file a bug report.

David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]