Hola! Estaria mal hacer un getter de building en la clase abstracta para despues acceder a getResidentialRoomExpense() y getCommercialMult() desde las hijas en lugar de hacer getters en la clase abstracta de esos mismos datos?
public abstract class FunctionalUnit{
private final String name;
private final int squareMeters;
private final Building building;
public FunctionalUnit(String name, int squareMeters, Building building){
this.name = name;
this.squareMeters = squareMeters;
this.building = building;
}
protected double calculateExpense(){
return squareMeters * building.getM2Expense();
}
protected Building getBuilding(){
return building;
}
@Override
public String toString(){
return "U.F %s ( %d m2 )".formatted(name, squareMeters);
}
}
public class ResidentialFunctionalUnit extends FunctionalUnit{
private final int rooms;
public ResidentialFunctionalUnit(String name, int squareMeters, int rooms, Building building){
super(name, squareMeters, building);
this.rooms = rooms;
}
@Override
protected double calculateExpense(){
return super.calculateExpense() + rooms * getBuilding().getResidentialRoomExpense();
}
@Override
public String toString(){
return "Residencial: %s : $%.2f".formatted(super.toString(), calculateExpense());
}
}
public class CommercialFunctionalUnit extends FunctionalUnit{
public CommercialFunctionalUnit(String name, int squareMeters, Building building){
super(name, squareMeters, building);
}
@Override
protected double calculateExpense(){
return super.calculateExpense() * getBuilding().getCommercialMult();
}
@Override
public String toString(){
return "Comercial: %s : $%.2f".formatted(super.toString(), calculateExpense());
}
}
Hola! Estaria mal hacer un getter de
building
en la clase abstracta para despues acceder agetResidentialRoomExpense()
ygetCommercialMult()
desde las hijas en lugar de hacer getters en la clase abstracta de esos mismos datos?