I am having a class with two instance variables.
class SomeName {
String a;
String b;
String c;
String d;
SomeName(String a, String c){
this.a = a;
this.c = c;
process(a,b);
process(c,d);
}
public void process(String a, String b){
// Some complex operation on 'a'
// instance variable 'b' is initialized based on the result
b = result;
}
}
Two of my class instance variable are initialized by calling my constructor. The others are initialized by doing some operation on the former variables. Now it is my understanding that calling the process method in constructor with instance variables as its parameters is bad design.
process(a,b);
process(c,d);
Is there any alternative ways to achieve the same which I am trying to do ?
In other words........
I am getting the value for 'a' from outside. I need to do some operation on that and assign it to 'b'. The same applies for 'c' and its pair 'd'. Since both are same operations I wrote that as a common method process() . But I am passing instance variables as arguments which is bad design. Please suggest an alternative for this bad design approach.
Aucun commentaire:
Enregistrer un commentaire