I'm a little bit confused about how to properly use getter and setter in some case.
Let's imagine for example a class named Car.
This Car has a maintenanceBook, and this one some information about the Car:
class Car() {
MaintenanceBook maintenanceBook;
}
class MaintenanceBook() {
String date;
String lastCall;
}
What is the best practice to access to the different parameters of the maintenanceBook:
- set all parameters to
publicand usecar.maintenanceBook.dateor... - implement getter and use
car.getMaintenanceBook().getDate();?