I have a main Class MyOne
which has an inner helper Class MyTwo
. I have created a private method loadValues
which will save all the local class variable data into an object, which will be used in the main class for applying different logic.
The code provided below is only a rough sample.The actual code is pretty complex.The problem is that the section between /***START***/
and /***END***/
is really long and I want each of my methods to follow the rule of thumb.
Please provide ideas as to how I can handle the code within section /***START***/
and /***END***/
. Should I be moving this section into another method? If so, how do I return all the modified variables myTwo.x,myTwo.z,myTwo.y
back into the mainExecution
method? I'm new to Java so any help would be very useful.
public class MyOne {
public mainExecution() {
MyTwo myTwo = loadValues();
List dataList = getData();
/****START*****/
if (dataList.size() > 0){
for (int j = 0; j <dataList.size(); j++){
currData = dataList.getDataRecord(j);
myTwo.b = currData.getStringVal();
if (myTwo.b.contains("New Detail")){
myTwo.z = (myTwo.x + myTwo.y)/60;
myTwo.y = myTwo.x;
}
else if (myTwo.b.contains("Old Detail")){
myTwo.z = (myTwo.y - myTwo.x);
}
else{
//More logic
}
}
}
/****END*****/
private MyTwo loadValues(){
MyTwo myTwo = new MyTwo();
myTwo.x = 12;
myTwo.y = 20;
myTwo.z = 55;
myTwo.a = "My Test Class";
myTwo.b = "";
return myTwo
}
private class MyTwo{
int x;
int y;
int z;
String a;
String b;
}
}
}
MyTwo
Class ??? – programmer_1 Feb 24 '12 at 6:25