I have below constructor, where it creates a workbook in constructor. I read that, ideally, we should not create objects in Constructor, instead, we should have just assignments which are passed.
public ExcelWriter() {
workbook = new HSSFWorkbook();
//other code
}
Is it okay to create fixed objects like above? What is ideal alternative solution? and from Unit Testing perspective? If to pass workbook from calling method code in other class, we have to create the workbook object even there also.
Is later is better approach? How it is better or matters compared to constructor approach?