jeudi 20 mai 2021

Modularizing configuration classes assembly - design question

In my codebase I'm using different configurations of a base server configuration pojo (includes only server address member).

  • In some of the cases I use only the server address and nothing more.
  • In some of the cases I need to use a server configuration which includes both address and protocol.
  • In some of the cases I need to use a server configuration which includes only address and a nickname for this server.
  • In some of the cases I need to user a server configuration which includes address, protocol, and path.

I think you get the point. I bumped into a need to be able to create a configuration class in a modular manner which is based on some atomic-configuration class components.
Currently, what I have is an inheritance tree that have the following structure:

                                       ServerConfiguration
                                               | 
                                     PortServerConfiguration
                                               |
                                  ProtocolPortServerConfiguration
                                               |                      \
                                NameProtocolPortServerConfiguration       PathProtocolPortServerConfiguration

If to keep this pace, I'm wondering what if I would need also a name property in most of these configuration classes. Another inheritances?! sounds bad. This begin to look like a real code smell and it's quite unreasonable to have an inheritance for gaining some additional members into configuration class.
Meanwhile I had been thinking towards some kind of decoration, but please note I need the ability to have getter methods for all members I have at the final composed configuration class. Thus I could not see how decoration could help.

Would appreciate your advice and thoughts,

Aucun commentaire:

Enregistrer un commentaire