When using composition, when should we favour wrapper methods? Let's say we have the classic car example.
public class Car {
private Battery battery;
//wrapper method
public void load(float p) {
this.battery.load(p)
}
}
public class Battery {
public void load(float percentage) {
}
}
The alternative would be to make a getter method that returns the battery so other code would load the battery like this car.getBattery().load(...)
, but then: should we return the reference or a clone? And what would be more future-proof?