The topic already says:
Now I am thinking about the following design problem: I am defining an interface for a specific type of object that contains various methods. Now I have a problem that different implementations of this interface require additional / different method parameters (because the method of their implementation makes this necessary), which I cannot include in the interface, because they are not common to all implementations of the interface.
Now I understand that interface implementations can come with their own properties files, loading additional parameters from them, but what if these parameters should be passed at runtime?
For now, I can only think of going to Map<String, Object> parameters to overcome this problem - because JDK classes like DocumentBuilderFactory do something very similar by providing methods like setAttribute(String attName, Object attValue) this seems to be an acceptable approach to solving this problem. Nevertheless, I would be interested in how others solve such problems, alternative ideas?
I do not want to extract from the interface and add additional methods, since in my case I would have to throw a NotImplementException from the methods of the base interface.
UPDATE
What could be the potential problems of the Map approach? Implementing classes can freely ignore it if they cannot use additional parameters. Others can check whether the Map contains the required parameter names, check the type of their values ββand use them if they are valid, throw an exception if not. I also saw that this is used for the abstract JAXBContext class, so this seems to be a general approach.
UPDATE
I decided to go to the map approach, since I do not see any obvious flaws, and it is also used in the JDK (yes, I know, this does not necessarily mean much :) Since I can not accept the answer to this question, I just come . Thanks for your input!
Yours faithfully,
- Qu
source share