package schemeFW; /** * Concrete IListFactory to manufacture IList as composites. * EmptyList and NEList are static nestes classes and hidden from all external * client code. * @author D.X. Nguyen */ public class CompositeListFactory implements IListFactory { private static class EmptyList implements IEmptyList { public final static EmptyList Singleton = new EmptyList (); private EmptyList() { } public Object execute(IListAlgo algo, Object inp) { return algo.emptyCase(this, inp); } } public class NEList implements INEList { private Object _first; private IList _rest; public NEList(Object dat, IList tail) { _first = dat; _rest = tail; } public Object getFirst() { return _first; } public IList getRest() { return _rest; } public Object execute(IListAlgo algo, Object inp) { return algo.nonEmptyCase(this, inp); } } public static final CompositeListFactory Singleton = new CompositeListFactory(); private CompositeListFactory() { } public IEmptyList makeEmptyList() { return EmptyList.Singleton; } public INEList makeNEList(Object first, IList tail) { return new NEList(first, tail); } }