Benutzer:Dirk Huenniger/ioc
Erscheinungsbild
Es gibt eine Box
class Box<T> {
private bool hasContend;
private T contend;
private Box<T>() {};
private T get() throws NoContendException {
if (!hasContend) { throw new NoContendException}
return contend;
};
private bool hasContend( return this.hasContend);
private put(T contend) throws HasContendException {
if (this.hasContend) {throw new HasContendException}
this.hasContend=true;
this.contend=contend };
}
Der User Definiert seine Interfaces
interface MyInterface1 {
MyType1A call(MyType1B x );
}
Hierraus genereiren wir automatisch die Proxinterfaces:
interface MyInterface1Proxy {
Box<MyType1A> call(Box<MyType1B> x );
}
Ferner generieren wir die Proxyfactory
class ProxyFactory {
Container container;
private ProxyFactory (Container c) {
this.container=container;
}
MyInterface1Proxy getProxyForMyInterface1(MyInterface1 i) {
return new MyInterface1ProxyImpl(container,i)
}
}
und generieren die Implementierende Klasse
class MyInterfaceProxyImpl implementes MyInterfaceProxy{
Container container;
MyInterface i;
MyInterfaceProxyImp(container,i) {
this.i=i;
this.container=container;
}
Box<MyType1A> call(Box<MyType1B> x ); {
Box<MyType1A> r =container.getEmptyBox<MyType1A>
List<Object> l= new LinkedList;
l.add(x)
container.addListener(new ListenerMyInterface1(r,l,i))
}
}
und generieren schließlich den Listener
class ListenerMyInterface1 exteneds Listener {
void call() {
r.put(((MyInterface1) i).call(MyType1B l.next()))
}
}
Wir haben den vielleicht konstanten Listener
class Listener {
Object r;
List l;
Object i;
Listener(Object r,List l){
this.r=r;
this.l=l;
this.i=i;
}
bool ready() {
for (Object o: l)
if (!((Box) o).hasContend) {
return false;
}
return true;
}
abstract void call()
}
Wir haben den konstanten Container
class Container {
List<Object> boxlist;
List<Object> listenerlist;
Container() {
boxlist=new LinkedList();
listener=new LinkedList();
}
static<T> Box<T> getEmptyBox() {
Box<T> b = new Box<T>();
boxlist.add(b);
return b};
static<T> Box<T> getFilledBox(T t);
Box<T> b = new Box<T>();
b.put(t)
boxlist.add(b);};
return b;
static void addListends(Listener l) {
listenerlist.add(l)
}
static void run() {
List rem=new LinkedList()
for (Object l:listernerlist) {
if (Listener l).ready() {
rem.add(l)
(Listener l).call();
}
}
listnerlist.removeall(rem)
}
}