Sunday, November 28, 2004

Some delphi guys complain that there are no class reference in java and .net, such as

type
BaseClass = class
constructor Create; virtual;
...
end;

BaseClassRef = class of BaseClass

DerivedClass1 = class (BaseClass )

DerivedClass2 = class (BaseClass )

RegisterClass(DerivedClass1);
RegisterClass(DerivedClass2);
...
var
AClassRef : BaseClassRef ;
begin

//the class name can be stored in a configuration profile
AClassRef := BaseClassRef(FindClass('DerivedClass1'));
...
end;


Now, we could do the similar thing with a java IOC framework PicoContainer.

Interface BaseIntf

class DerivedClass1 implements BaseIntf

class DerivedClass2 implements BaseIntf

public void () {
MutablePicoContainer pico = createPicoContainer(null);
pico.registerComponentImplementation("DerivedClass1",DerivedClass1.class);
pico.registerComponentImplementation("DerivedClass2",DerivedClass2.class);
...

//the class name can be stored in a configuration profile
BaseIntf t = (BaseIntf) pico.getComponentInstance("DerivedClass2");
assertNotNull(t);
}


PicoContainer has .net portion too.

No comments: