Right now I am creating a load of classes that will hold my configuration and that is it. All I do is store the values from the configuration file.
More than half the code is the getters and I am wondering whether the practice is still to have the getters or just access the variables directly.
So this:
public myClass
{
public myClass(String name)
{
this.name = name;
}
final String name;
public final String getName()
{
return name;
}
}
Or:
public myClass
{
public myClass(String name)
{
this.name = name;
}
public final String name;
}
It seems really silly to have all the getters there when they are not actually doing anything but return the variable. But I have been told that it is common Java practice to have the getter in there anyways.
Encapsulating the data with getters can provide several advantages, including:
final
. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With