Note that there are some explanatory texts on larger screens.

plurals
  1. PODesign Pattern for a "library" in Java?
    text
    copied!<p>I'm looking for a design pattern for a set of methods which will be used in several projects so I'm making a "library" with them.</p> <p>At first I thought of making all of them static so they could be called by Library.methodName() and that's it. I did and realized I was passing around a couple of constant values for every method which can set once and then used inside the class. (This constant values change between projects)</p> <p>Now I thought of having a Class which has to be instantiated with this values and access the methods trough the object without passing the values every time, however I want to prevent the creation of objects of the "Library" class every time so I thought of Singleton.</p> <p>I did make a Singleton with all of this, however I need to make an explicit <code>set</code> for the class variables at first, but this approach requires the programmer to now that the value has to be set before using the methods, which will make it fail for sure eventually, even by myself.</p> <p>doing <code>Singleton.getInsance(value1, value2).method(...)</code> all the time is out of the question, I'd prefer my initial approach. Also, I can't define a "default" value for this variables, they HAVE to be set.</p> <p><strong>Is there a design pattern that will help me have a Singleton which can be initialized with given values and not having to pass them around all the time?</strong> </p> <p>or should I just stick with my initial approach and make the programmer pass the values all the time?</p> <p>or any other option, any design pattern that fits, or anything else may also work.</p> <p>Thanks</p>
 

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