So I'm going back and forth about whether or not to use getters and setters and any alternatives if I don't. I've read some articles that say getters and setters should be avoided at all cost.
But I have an example program here, with a class called FlightInfo which basically holds all of the flight information such as flight date and the flight number. Wouldn't it be easiest to use getters and setters like the following:
public class FlightInfo {
private String date;
private int flightNumber;
public String getDate(){
return date;
}
public setDate(String date){
this.date = date;
}
public int getFlightNumber(){
return flightNumber;
}
public setFlightNumber(String flightNumber){
this.date = flightNumber;
}
}
Is there any better alternative to this? Also, the flight date may change for a particular flight number.
Thanks.
Edited by: java_fan_69 on Dec 5, 2007 10:33 AM