我有一个只有 main 的类,它读取一些 txt 并执行算法。
我的课看起来像:
class doThejob{
public static void main(String args[]){
//*****start part A******
//do the reading from text file, and tokenize it
// process into the form I need,
//about 10-30 lines of codes
//******End of part A*****
//then run the algorithms
algorithm alg=new aglorithm();
Object output = alg.x(input);
//****Part B**** output to txt, about 10~40 lines
}
}
class algorithm{
private void a(Object x){
//do something
return (Object)result;
}
}
谁能告诉我是否应该将这些 A 部分和 B 部分提取到一个新类中,然后将它们设置为公共方法。如下所示
class Io{
public Object readFromTxt(String path){
}
public void outputToTxt(String path){
}
}
如果我设置它们,然后像下面这样使用它,那是不是更多的 OOP?
class doThejob{
public static void main(String args[]){
Io dataProcess= new Io();
Object input = dataProcess.readFromTxt(args[0]);
algorithm alg=new aglorithm();
Object output =alg.x(input);
dataProcess.readFromTxt(args[1],output);
}
}
class algorithm{
private Object a(Object x){
//do something
}
}