I read Leo Simons story of the little component that could.
The basic idea was...
...that everything should be passed in the
constructor
...that all components are what we would call
ThreadSafe/Singleton, i.e. you get one reference
and can keep it.
Now, suppose I have a component with about 20 parameters and
four other dependencies.
I get a constructor with 24 parameters. And the constructor itself
will be 24 lines of:
this.m_variable = variable;
I hate it when that happens.
So I returned to thinking about how a container can set the values
and start up a component without having to code all those assignment
statements.
Dependencies are easy:
/**
* @@Dependency()
*/
private final MailServer mailServer;
Tells the container to set this field to a MailServer component.
But configuration? Well, suppose we restricted ourselves to this:
Each configurable field in a component implementation is either:
+ A primitive value (double, int, boolean, etc.)
+ A class with a (String) constructor.
+ A class with a (Configuration) constructor.
+ A class that in turn has configurable fields.
Then we can map each configuration entry into a field:
/**
* @@Configuration ("@max-threads")
*/
private final int maxThreads;
/**
* @@Configuration ("background-color")
*/
private final Color backgroundColor;
/**
* @@Configuration ("foreground-color")
*/
private final Color foregroundColor;
class Color {
/**
* @@Configuration ("@red")
*/
int red;
/**
* @@Configuration ("@green")
*/
int green;
/**
* @@Configuration ("@blue")
*/
int blue;
}
And then use a configuration like this:
<component max-threads="8">
<foreground-color red="255" green="255" blue="255"/>
<background-color red="255" green="255" blue="255"/>
</component>
In short, this would allow us to move the setting of fields
to the container. The container can access private fields via the
AccessibleObject.setAccessible, provided that the container class
has the required security permissions (which I assume it can be
given - it is the only class that needs it).
Thoughts?
/LS
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]