I was reading through testable code that follows LoD, but got all messed up in my head. So please any guidance regarding this piece of code would be appreciated.
public class HouseConfiguration {
private final int noOfDoors;
private final int noOfWindows;
//.... And so on
public HouseConfiguration(int noOfDoors, int noOfWindows){
this.noOfDoors = noOfDoors;
this.noOfWindows = noOfWindows;
//.....
}
//getters for config
}
public class Contractor {
public House buildHouse(HouseConfiguration houseConfiguration) throws Exception{
validateHouseConfiguration(houseConfiguration);
Window[] windows = new Window[houseConfiguration.getNoOfDoors()];
return new House(windows);
}
private void validateHouseConfiguration(HouseConfiguration houseConfiguration) {
//validation logic
}
}
public class House {
private Window[] windows;
//Now as the parameters increase it becomes a problem to pass so many arguments in constructor
public House(Window[] windows /*Also other arguments */) {
this.windows = windows;
}
}
Now as the arguments of the House
constructor increase it would be difficult to manage it using constructor. Lots of dependencies would be getting passed. Is it a correct thing to do? Or is there a better way that this code can be refactored?
EDIT:
Referring to the House
constructor arguments