lundi 16 mai 2022

Is splitting a class in two different class a good idea?

For a project I need to create report from Excel files.

But I have a big design question that I can't solve myself and I haven't found a solution online.

Here is what I'm trying to do :

  1. Read the content of an Excel file
  2. With that content initialize a new Report class
  3. Profit!

But the problem is that, the first time I wrote that, I put everything inside my Report class (by everything I mean reading the file, formatting the fields, etc ...) and I ended up with a big class.

I wasn't satisfied with that so I tried to do something better and created a ReportReader class that contain all my reading file stuff and also getters to init a Report class. It is a good idea or should I stick to one class ?

Also, could it be a good idea to create a createReport method inside ReportHeader instead of making public getters available ?

Thanks in advance for your responses.

public class ReportReader {
private final File file;
private final Sheet sheet;

public ReportReader(File file) throws InvalidFormatException, IOException {
 
}

public ArrayList<String> getFields() {

}

private String formatField(String input) {

}

public String getName() {

}

public Cell[][] getContent() {

}

public String getType() throws IOException {

}

}

public class Report {
private String name;
private String type;
private ArrayList<String> fields;
private Cell[][] content;

public Report(String name, String type, ArrayList<String> fields, Cell[][] content) throws IOException {

}

public void saveFieldsModel() throws IOException {

}

public String getFieldsAsCsv() {

}
}

Aucun commentaire:

Enregistrer un commentaire