Thiscodesolves the problem.But it is veryverbosesolution.
public abstract class Grammar01Factory { public fun method01() { }}open public class Grammar01 { open public class object: Grammar01Factory() { }}public abstract class Grammar02Factory: Grammar01Factory() { fun method02() { }}open public class Grammar02 { open public class object: Grammar02Factory() { }}public abstract class Grammar03Factory: Grammar02Factory() { fun method03() { method01() }}open public class Grammar03 { open public class object: Grammar03Factory() { }}fun test() { Grammar03.method01() Grammar03.method02() Grammar03.method03()}
The existing classes aremore complexand they arestatic.
class Grammar { static public Rule matchString(String s) { return new Rule(); } static public Rule matchChar(Character c) { return new Rule(); } static public void initGrammar(Class<?> clazz) { // init using reflection }}class SharedGrammar extends Grammar { public static Rule function = matchString("def"); public static Rule comma = matchChar(','); static { initGrammar(SharedGrammar.class); }}// inherit and extends and override some fields and propertiesclass BasicGrammar extends SharedGrammar { // override SharedGrammar public static Rule function = matchString("fun"); public static Rule equals = matchString("=="); static { initGrammar(BasicGrammar.class); }}// inherit and extends and override some fields and propertiesclass ConcreteGrammar extends BasicGrammar { // override BasicGrammar public static Rule equals = matchString("==="); static { initGrammar(ConcreteGrammar.class); }}
It is possible, of course,be rewrittento usedynamic classes. But it willnotquite whatit actually is. And thepracticeis not always possibleto change something.
Features of the languagedoes not always allowhim tobe back-end(parentclasses) for Java.Rather, it isfront-end. Orequal,but notfully compatible with Java.Or,even better thanJava,but not replaceJavacompletely.