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

Re: Tim Sweeney on Programming Languages



Bruce Hoult <brucehoult@pobox.com> wrote:

> He doesn't really give many details of what he *does* want, other than the
> idea of "virtual classes".  This basically seems to be a convenience
> feature that if you have related classes A, B, and C, you can nest them
> inside another construct such that you can derive a set of new classes A',
> B' and C' in one step.

I don't remember Sweeney's article very well, but the lasting impression
_why_ he wants this kind of mechanism seems to be that it allows to
change/enhance classes that live "in the middle" of a framework. Unless
I'm missing something it's no big deal to get exactly this effect in a
language such as Java like this:

public BaseClass {

    public interface VirtualInnerClass {...}
    
    // ordinary methods go here...
    
    protected VirtualInnerClass createVirtualInnerClass() {
        return new ConcreteInnerClass();
    }
    
    protected class ConcreteInnerClass implements VirtualInnerClass {
        //...
    }
}

public DerivedClass extends BaseClass {

    //...
    
    protected VirtualInnerClass createVirtualInnerClass() {
        return new DerivedConcreteInnerClass();
    }
    
    protected DerivedConcreteInnerClass 
        extends ConcreteInnerClass {
        //...
    }
}

(Yes, I excuse for the Java, but that is what I have to use right now.)

More or less this comes down to a variation of the Factory Method
pattern. The real problem is not to implement this, rather it is to know
when to use it. In Java or C++ this kind of flexibility has to be
build-in beforehand. But the cases where you really need it are those
where no-one thought of it before.

In Dylan, the case is different, simply because behavior can be added to
existing classes a lot easier. I'm not sure about what's involved in
adding state; can this be done by specializing make? (Yes, again, it
figures that I'm spending too little time with Dylan.)

Michael

-- 
Michael Schuerig
mailto:schuerig@acm.org
http://www.schuerig.de/michael/



References: