Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config files - public properties #1

Open
adelgadocabrera opened this issue Apr 4, 2022 · 2 comments
Open

Config files - public properties #1

adelgadocabrera opened this issue Apr 4, 2022 · 2 comments

Comments

@adelgadocabrera
Copy link
Collaborator

adelgadocabrera commented Apr 4, 2022

I don't know if it is good practice, but for config classes such as ApplicationConfig, BrokerConfig etc... I normally tend to have the properties as public to avoid having to code getters.

The main reason is that, I as yourself, have set these properties as final, so client shouldn't be able to change the values. I understand that perhaps one of the properties may be a mutable list/map.

But could still could be convenient at a times.

@anchitbhatia
Copy link
Owner

It probably does not matter in case of configuration files. I tend to use getter methods to adhere to OOP design and therefore avoid using public members wherever i can.

Just being curious, if you dont have getter methods then how are you accessing non static data members outside the class?

@adelgadocabrera
Copy link
Collaborator Author

ye... but I don't know... I think it still adheres to oop designs if you cannot change the value (final). Also, java is so so verbose, having to create getters for lots of properties sometimes gets a bit ridiculous.

If you have a class like

class Config {
   public final String name;
   public final int age;
   ...
}

Simply access the properties like:

Config config = new Config("alberto", 31, ...);
String name = config.name;
int age = config.age;
...

Those properties are immutable so its all good. But this is very opinionated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants