At work we have a class that is essentially a large class containing a private variable with corresponding getter and setter functions. Now, in the beginning this wasn’t a problem; only 4 or 5 members in this class and it was maintainable and easy to modify. That is not the case now. I just had to go add a new member to the class and was forced to look at the ugly mess of code in that file and I finally though “enough is enough”. So now I’m trying to think of a better way to store these variables.
For instance, in C# we have ‘inline’ getter and setter functions:
private string variable { get; set; }
That’s awesome. Obviously Java has nothing like this, but I’m still trying to find a way to reduce the lines of code one needs to type to just add one variable to a class.
Theoretically I could use a map of some sort, but I feel that’s overkill for something as simple as this. Is there some kind of design pattern I’m missing? I just want to find a way to easily declare a variable that will be accessed only once per instance without the clutter and mess of those getter and setter functions. This is kind of a noob question, but there has to be a more dynamic way, right?
Right?