Note that there are some explanatory texts on larger screens.

plurals
  1. POOOP-Design: Interface-Methods with implementation-dependent parameters
    primarykey
    data
    text
    <p>The subject says it already: </p> <p>I am thinking right now about following design-problem: I define an interface for a specific type of object that contains various methods. Now i have the problem, that different implementations of this interface, need additional/different method-parameters (because the way they are implemented makes this necessary), which i cannot incorporate into the interface because they are not common to <em>all</em> interface-implementations.</p> <p>Now i realize that interface implementations could come with their own property-files, loading their additional parameters from there, but what if these parameters need to be passed in at runtime?</p> <p>Currently i can only think of passing in a <code>Map&lt;String, Object&gt; parameters</code> to overcome this problem - since JDK-Classes like <a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFactory.html" rel="nofollow">DocumentBuilderFactory</a> are doing something very similar by providing methods like <code>setAttribute(String attName, Object attValue)</code> this seems like a feasible approach to solve this problem. Nevertheless i would be interested in how others solve issues like this, alternative ideas?</p> <p>I dont want to derive from the interface and add additional methods, since in my case i would then have to throw <code>NotImplementException</code> from the methods of the base interface.</p> <p><strong>UPDATE</strong>:</p> <p>What could be eventual problems of the Map-approach? Implementing classes are free to ignore it completely if they cant make use of additional parameters. Others might check if the Map contains the desired parameter-names, check the type of their values and use them if valid, throw an exception if not. I have also seen this being used for the abstract class JAXBContext, so it seems to be a common approach..</p> <p><strong>UPDATE</strong>:</p> <p>I decided to go for the map-approach, since i dont see any obvious disadvantages and it is being used in the JDK as well (yes, i know this does not necessarily mean much :) Since i cannot accept an answer on this question, i will just upvote. Thanks for your input!</p> <p>regards,</p> <p>--qu</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload