I am looking for a suitable design which uses composition to allow three classes to share some logic.
The problem I am solving is that I have to read 3 different json configuration files from my application, and each file needs to have a different class that allows to filter specific data accordingly, however I need to share the logic of reading the files from the filesystem and validating the schema and format. I am looking to avoid inheritance and use composition instead, and I am trying to avoid repeating code as much as possible.
The three classes I currently have are:
CompanyConfig getCompanies() getCompany() RoleConfig getRoles() getRole() getRolesBy() ThemeConfig getThemes() isThemeEnabled()
On each of these classes constructors I am using a class LoadFileContents and ValidateFileContents, however the logic to invoke these two classes repeats on each of the config classes.