I am currently developing an API where I want to enable customization using various methods. One of the methods is through the XML configuration scheme, and the other is through the API, which I want to play well with Spring.
My XML Schema syntax code was previously hidden, and so the only problem was for it to work, but now I want to create a public API, and I am very concerned about best practice.
Many seem to prefer a javabean of type PoJo with default null parameter constructors and then setting the injection. The problem I'm trying to solve is that some implementations of setter methods depend on other setter methods that are called before them in sequence.
I could write anal setters that will endure themselves, called in many orders, but this will not solve the problem that the user forgot to install the corresponding setter and, therefore, the bean is in an incomplete state.
The only solution I can think of is to forget about the objects, 'beans', and force the required parameters using the constructor insert.
An example of this is the default value for a component identifier based on the identifier of the parent components.
My interface
public interface IMyIdentityInterface {
public String getId();
public void setId(String id);
public IMyIdentityInterface getParent();
public void setParent(IMyIdentityInterface parent);
}
Basic implementation of the interface:
public abstract class MyIdentityBaseClass implements IMyIdentityInterface {
private String _id;
private IMyIdentityInterface _parent;
public MyIdentityBaseClass () {}
@Override
public String getId() {
return _id;
}
@Override
public void setId(String id) {
if (id == null) {
IMyIdentityInterface parent = getParent();
if (parent == null) {
} else {
_id = Helpers.makeIdFromParent(parent,getClass());
}
} else {
_id = id;
}
}
@Override
public IMyIdentityInterface getParent() {
return _parent;
}
@Override
public void setParent(IMyIdentityInterface parent) {
_parent = parent;
}
}
Each component in the structure will have a parent, with the exception of the top-level component. Using the type of setup for injection, setters will have different behavior based on the order in which the setters are called.
, , , , ? , IoC?