LoggableComponent ?

Tom Zeller tzeller at dragonacea.biz
Wed Jun 19 14:39:29 EDT 2013


> To my mind since this is function which is only of use within the class and
> its children I think that an interface is overkill; I just don't see what it
> buys us.  After all, this is not something that we want have available to
> other classes; indeed quite the contrary - it is purely a convenience
> mechanism within a class and its children to make sure that all log messages
> look consistent.   Or am I missing something?

I thought it worthwhile to consider "standardizing" getLogPrefix() via
an interface because it appears in classes that span
modules/components and because it is often inherited (attribute
definitions and matchers). For clarity.

> "Up to a point", I would not be against seeing it pushed down to the base
> Identifiable classes (since the paradigm used throughout the code is the
> same and the only variant is the prefix).  But this falls into complexity
> really soon:
>  - We'd need to add a new method to them to set the prefix
>  - Then we'd need to ensure that it was non null in the initialize call,

When I see methods like

protected String getLogPrefix() {
  String prefix = logPrefix;
  if (null == prefix) {
    StringBuilder builder = new StringBuilder ...
    prefix = builder.toString();
    if (null == logPrefix) {
      logPrefix = prefix;
    }
  }
  return prefix;
}

I think that kind of logic should be done during initialization.

>  - Which would break all the users of the code who are not us

Not following, could you say more ?

> "AbstractIdentifiableInitializableWithLogprefixComponent"

A class name like that would probably result in someone making fun of
it on a blog somewhere, titled
HorriblyLongJavaNamesBecauseOfSingleInheritance.


More information about the dev mailing list