P
puzzlecracker
I have an interesting problem to which I have written a solution I don'
t like.
Here is a sample static class (followed by more precise requirements):
public class Initializer{
private String name ="DefaultName";
private SomeUtil utility=null;
private static void init(){
if (utility!=null){
return;
}
//initialize utility with name
}
static void setName(String name){
this.name=name;
}
static T someOp1 (T t){
init();
//some stuff
}
static T someOp1 (T t){
init();
//some stuff
}
static T someOp1 (T t){
init();
//some stuff
}
//***
}
Above utility class, can only be used when utility is initialized with
specific name. I accomplish that by either setting the name or calling
an operation, that performs a dirty check to decide whether
initialization is needed, and if so - default name is set
Support initialization is expensive and doing more than once in not
desirable.
I don't like the above solution because it calls init on every
operation.
Can someone suggest an alternative, more elegant solution (perhaps
along the AOP lines )?
Thanks
t like.
Here is a sample static class (followed by more precise requirements):
public class Initializer{
private String name ="DefaultName";
private SomeUtil utility=null;
private static void init(){
if (utility!=null){
return;
}
//initialize utility with name
}
static void setName(String name){
this.name=name;
}
static T someOp1 (T t){
init();
//some stuff
}
static T someOp1 (T t){
init();
//some stuff
}
static T someOp1 (T t){
init();
//some stuff
}
//***
}
Above utility class, can only be used when utility is initialized with
specific name. I accomplish that by either setting the name or calling
an operation, that performs a dirty check to decide whether
initialization is needed, and if so - default name is set
Support initialization is expensive and doing more than once in not
desirable.
I don't like the above solution because it calls init on every
operation.
Can someone suggest an alternative, more elegant solution (perhaps
along the AOP lines )?
Thanks