On Tue, Oct 11, 2005 at 06:10:41PM -0400, Stevan Little wrote:

> I would like to propose that class methods do not get inherited along  
> normal class lines.

You mean, make them *not methods?* Because it's not a method unless it
has an invocant, as far as I'm concerned. (Method implies polymorphism.)

: Let's start by making a very basic definition of an *object*,  
: ignoring any implementation details or specifics.
:   object == state + behavior

I don't see how this is a bad thing. Classes don't have state. That's
their lot in life. Que sera! Inheritance of behavior alone is useful.

My primary want for class methods, as a whole, is to provide this sort
of interface in Objective-C:

    @interface Host : NSObject {
    - (Class)plugInClass;
    - (void)setPlugInClass:(Class) plugInClass;

    @interface PlugIn : NSObject {
    - (BOOL)initWithHost:(Host *)host;
    + (BOOL)supportsFeatureA;
    + (BOOL)supportsFeatureB;

    ... later ...
    if ([[host plugInClass] supportsFeatureA]) {
        ... expose UI element ...

Rather than having to make plugin creation cheap so that I can do this:

    class Host {
        public Type PlugInClass {
            get { ... }
            set { ... }

    class PlugIn {
        public bool Host { get; }
        public abstract bool SupportsFeatureB { get; }
        public abstract bool SupportsFeatureA { get; }

    ... later ...
    PlugIn plugIn = (PlugIn) Activator.CreateInstance(host.PlugInClass);
    if (plugIn.SupportsFeatureA) {
        ... expose UI element ...

Another alternative is to introduce a PlugInFactory. Which might be
better in complex scenarios. But it's often overkill. And it's certainly
more typing.

In C#, I might also use attributes to decorate the plugin Type. But
those, too, are more typing than class methods (and also weakly typed).

Also, of course, inheriting constructors is nice. Of course, it opens up
the whole "designated constructor" can of worms. But that's okay; if
you're subclassing, it's your responsibility to make it work....

Gordon Henriksen

Reply via email to