> > public class SimpleInstantiationExpression {
> > private Class klass;
> > public SimpleInstantiationExpression(Class klass) {
> > this.klass = klass;
> > }
> > public Class getType() { return klass; }
> > public Object getValue() {
> > try {
> > return klass.newInstance();
> > } catch (AllRelevantExceptions are) {
> > throw new ReleventException(are);
> > }
> > }
> > }
>
> with a few exceptions (like the getName as get and set express something
> simple like an accessor to some internal value and not to instantiate
> something IMO) I like what I see.
Expression is sort of an alternative to ComponentAdapter. It has the same
semantics, but I left off some of the extras. I agree that getValue is very
non-descriptive for instantiation, but it makes sense in terms of an
Expression (especially a caching one).
public interface ObjectReference {
Object getObject();
void setObject(Object o);
}
public class CachingExpression
implements Expression {
private Expression root;
private ObjectReference ref;
public CachingExpression(Expression root, ObjectReference ref) {
this.root = root;
this.ref = ref;
}
public Class getType() { return root.getType(); }
public Object getValue() {
Object o = ref.getObject();
if (o==null) {
o = root.getValue();
ref.setObject(o);
}
return o;
}
}
> but is it a decorator or chain of responsabilities? I'd rather the second
> drawing.
I was thinking decorator. But if you can explain how you would use a
chain-of-responsibilities pattern, I would be interested.
My intended use was something like:
public interface Concern {
Expression passOnConcern(Container c, Object key, Expression exp);
}
public class LogEnablingConcern
implements Concern {
private Logger logger;
public LogEnablingConcern(Logger logger) {
this.logger = logger;
}
public Expression passOnConcern(Container c, Object key, Expression exp)
{
if ( exp.getType().isAssignableFrom(LogEnabled.class) ) {
return new LogEnablingExpression(exp, logger);
} else {
return exp;
}
}
}
public class LogEnablingExpression
implements Expression {
private Expression root;
private Logger logger;
public LogEnablingExpression(Expression root, Logger logger) {
this.root = root;
this.logger = logger;
}
public Class getType() { return root.getType(); }
public Object getValue() {
Object value = root.getValue();
( (LogEnabled) value ).enableLogging(logger);
return value;
}
}
Jonathan Hawkes
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]