Domanda

Here, AsciiChecker enables the matrix specification in the text form.

abstract class AsciiChecker extends AlgoritmicChecker {

    String[] ascii;

    AsciiChecker(String title, final String ... ascii) {
        super(title, ascii[0].length(), ascii.length); // calls isCovered
    };

    boolean isCovered(int test, int statement) {
        return ascii[statement].charAt(test) == '1';
    }           
}

It needs the matrix argument to be available in the isCovered call. Tell me how do I shoot my leg if I initialize the field before using it,

    AsciiChecker(String title, final String ... ascii) {
        this.ascii = ascii;
        super(title, ascii[0].length(), ascii.length); // calls isCovered
    };

Nessuna soluzione corretta

Altri suggerimenti

If your superclass is using data your array, pull up String[] ascii; to the superclass, initialize this field there and in isCovered access it via getter or modify signature of isCovered and pass proper array as an argument.

You need to get rid of that call of an overrideable method in the superclass. From Effective Java, item 18:

Move the body of each overridable method to a private "helper method" and have each overridable method invoke its private helper method. Then replace each self-use of an overridable method with a direct invocation of the overridable method's private helper method.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top