Private or public variables??
I am due to submit some work on Friday. The program is comprised of about 15 classes and works fine in that it does what it is supposed to do. However, in one of the classes in particular I have a ton of public variables set at the start that other classes use. Should I encapsulate all of them? I'm not looking for improved performance, just better coding. Any criticism/suggestions welcome
Re: Private or public variables??
general convention says you should encapsulate, but I think that if the variables can be set to any possible value at any time, there's nothing wrong with leaving them public. Another thing you could consider is making some variables final and then leaving them public.
edit:
Oh, and as a side not, encapsulation should have a negligible effect on performance. If it doesn't, then usually (not always, though) that means something's wrong ;)
Re: Private or public variables??
My answer would be yes, please do, its the correct thing.
// Json