Implementation of type facet and type decorator.
- By Chung-Yeung Pang
- May 1, 2001
A Design Pattern for Type Extension With Facets and Decorators
by Chung-Yeung Pang
Listing 1. Implementation of type facet and type decorator.
package Type_Extension;
public class ExtensibleObject {
public String objName = null;
public java.util.Hashtable decorator = null;
public ExtensibleObject() {}
public void setName(String _name) {
objName = _name;
}
}
public class TypeFacet {
public ExtensibleObject me;
public TypeFacet(ExtensibleObject exObj) {
me = exObj;
}
}
public class TypeDecorator extends
ExtensibleObject {
public ExtensibleObject me;
public TypeDecorator() {
}
public void decorate(ExtensibleObject myObj) {
me = myObj;
if (myObj.decorator == null)
myObj.decorator =
new java.util.Hashtable();
if (name == null)
name = this.getClass().getName();
myObj.decorator.put(name, this);
}
}