Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Alternatives to forcing subclass to have a static method
    primarykey
    data
    text
    <p>I often find I want to do something like this:</p> <pre><code>class Foo{ public static abstract String getParam(); } </code></pre> <p>To force a subclasses of Foo to return a parameter. </p> <p>I know you can't do it and I know why you can't do it but the common alternative of:</p> <pre><code>class Foo{ public abstract String getParam(); } </code></pre> <p>Is unsatisfactory because it requires you to have an instance which is not helpful if you just want to know the value of the parameter and instantiating the class is expensive.</p> <p>I'd be very interested to know of how people get around this without getting into using the "Constant Interface" anti pattern. </p> <p>EDIT: I'll add some more detail about my specific problem, but this is just the current time when I've wanted to do something like this there are several others from the past.</p> <p>My subclasses are all data processors and the superclass defines the common code between them which allows them to get the data, parse it and put it where it needs to go. The processors each require certain parameters which are held in an SQL database. Each processor should be able to provide a list of parameters that it requires and the default values so the configuration database can be validated or initialised to defaults by checking the required parameters for each processor type. Having it performed in the constructor of the processor is not acceptable because it only needs to be done once per class not once per object instance and should be done at system startup when an instance of each type of class may not yet be needed.</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