Skip navigation.
 
mlRe: why are private classes private?
FROM : Mike Ferris
DATE : Mon Jan 06 08:12:02 2003

The standard way to do this is using the combination of subclassing and
containment that was mentioned earlier on this thread.  NSColor is
possibly a bit tougher than most class clusters since the NSColor class
defines a number of methods that are really only implemented by one of
the private subclasses (ie asking for the redComponent of a
non-rgb-backed NSColor is not supported.

But for most class cluster classes, you make a subclass that in turn
uses an instance of the base class (really one of its private
subclasses) and forwards methods along to that instance (usually via
explicit overrides of the cluster's primitives, not using
-forwardInvocation:...)  This has a bit of a memory cost, and most
method calls become two method calls as they get forwarded.  Depending
on the specific use, this can be significant although often isn't.

Class clusters are a bit of a pain, it must be admitted, for
subclassers who want to extend functionality.  (They are no different
from anything else, typically, if your intent is to fully replace the
core functionality of the class...)

Someone else suggested categories.  If what you're doing does not
require overriding methods, but just adding them, categories are a good
way around this whole issue.  You can even effectively add ivars with
the category through clever use of a static CFDictionary or
NSMapTable...

Mike Ferris



Related mailsAuthorDate
mlsubclassing a private subclass James Gregurich Jan 2, 16:07
mlRe: subclassing a private subclass John C. Randolph Jan 2, 16:19
mlRe: subclassing a private subclass James Gregurich Jan 2, 19:03
mlRe: subclassing a private subclass Finlay Dobbie Jan 3, 04:37
mlwhy are private classes private? James Gregurich Jan 3, 05:56
mlRe: why are private classes private? Finlay Dobbie Jan 3, 06:21
mlRe: why are private classes private? Clark S. Cox III Jan 3, 06:21
mlRe: why are private classes private? Mike Ferris Jan 3, 09:44
mlRe: subclassing a private subclass John C. Randolph Jan 3, 17:04
mlRe: subclassing a private subclass John C. Randolph Jan 3, 17:07
mlRe: why are private classes private? James Gregurich Jan 3, 19:02
mlRe: why are private classes private? Finlay Dobbie Jan 4, 04:21
mlRe: why are private classes private? Eric Peyton Jan 4, 05:53
mlRe: why are private classes private? Gregory Seidman Jan 4, 07:55
mlRe: why are private classes private? Kenneth C. Dyke Jan 4, 12:26
mlRe: why are private classes private? Mike Ferris Jan 6, 08:12