lundi 6 août 2018

Nested classes and good practices

I'm considering using nested classes in my class. I have a class called ServerConfiguration and I have two classes closely related to it: a builder and a provider.

All of the classes are in separate places:

  • hosting.core.server.ServerConfiguration
  • hosting.core.server.server_configuration.Provider
  • hosting.core.server.server_configuration.Builder

the question is if should I add them as nested (static) classes to the ServerConfiguration or keep it as is?

The ServerConfiguration class is very simple and adding 2 extra classes will make it more complicated. On the other hand, it's more readable to me to have code

private ServerConfiguration.Builder getBuilder() { return new ServerConfiguration.Builder(); }

instead of

private Builder getBuilder() { return new Builder(); }

what do you think?

Aucun commentaire:

Enregistrer un commentaire