Re: How do I create a mutable version of my object?
Re: How do I create a mutable version of my object?
- Subject: Re: How do I create a mutable version of my object?
- From: Philippe Mougin <email@hidden>
- Date: Tue, 21 Jan 2003 14:35:56 +0100
Jens Bauer wrote:
>I'm afraid of the overhead of NSObject. If it contains too many
>instance-variables, then it'll quickly grow huge. On the other hand,
>if NSObject already knows how to "repeat" a subclass (which I think
>might be difficult for NSObject), it would only add the overhead
>once.
When programming in Cocoa you must make your class inherit from one of
the root classes provided by Cocoa (i.e. either NSObject or NSProxy),
unless you are doing extremely uncommon things. For most purpose, you
should inherit (directly or indirectly) from NSObject. It is the
standard root class for all "regular" objects.
Also, I will second what Chris wrote: you should have a look at "The
Objective-C Programming Language" manual before going further.
>It can be difficult (and completely transparant to the user), whether
> the array-class has 32 pointers to each object, or a cluster of 32
> indexed objects, you see what I mean?
If your goal is to make an optimized array (or mutable array) you
should subclass the NSArray or NSMutableArray classes. At first glance,
this can be surprising, but subclassing these classes does not add any
memory overhead (these classes don't have any instance variable except
for the "isa" variable inherited from NSObject, which is a pointer to
the class of the object, something that is needed in every object).
They are designed to let you provide an optimized implementation if you
need to. To learn about this, read about Cocoa class clusters at
http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/
ProgrammingTopics/Foundation/Concepts/ClassClusters.html and
http://www.cocoadev.com/index.pl?ClassClusters. "Class cluster" is an
extremely well designed and useful Cocoa concept. I use it in one
project to provide optimized numerical and boolean arrays and it works
very well.
Best,
Phil
_______________________________________________
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.