Most ObjectOrientedLanguages support the super concept for calling its ancestors' methods. Some other languages, like BetaLanguage, allows usage of the inner concept for defining its children's behavior, a la TemplateMethodPattern. Inner provides a cleaner and more powerful concept than TemplateMethods, because you can have several layers of inner, where the TemplateMethodPattern allows just one per TemplateMethod.
Unfortunately, these concepts are mutually exclusive, so here is the question: in the real world, is super availability is really necessary? All uses I've seen of super seems to fall in two categories: poor man's template method (a la JavaLanguage constructor semantics) or incorrect use of inheritance instead of composition.
Could you explain what "the inner concept" is, what it means to "have several layers of inner", and why "these concepts are mutually exclusive"? I don't think I understand.
Sorry, I'll try to explain it using a JavaLanguage example:
public abstract class Parent { public abstract void setUp(); public abstract void tearDown(); public abstract void doExecute(); public void execute() { System.out.println("Parent.execute - before"); setUp(); doExecute(); tearDown(); System.out.println("Parent.execute - after"); } } public abstract class Child extends Parent { public void setUp() { System.out.println("Child.setUp"); } public void tearDown() { System.out.println("Child.tearDown"); } public void doExecute() { System.out.println("Child.execute - before"); doExecute2(); System.out.println("Child.execute - after"); } public abstract void doExecute2(); } public class GrandChild extends Child { public void doExecute2() { System.out.println("GrandChild.execute"); } }It should print:
Parent.execute - before Child.setUp Child.execute - before GrandChild.execute Child.execute - after Child.tearDown Parent.execute - afterIf JavaLanguage supported the inner concept it could be written as:
public abstract class Parent { public abstract void setUp(); public abstract void tearDown(); public void execute() { System.out.println("Parent.execute - before"); setUp(); inner(); tearDown(); System.out.println("Parent.execute - after"); } } public abstract class Child extends Parent { public void setUp() { System.out.println("Child.setUp"); } public void tearDown() { System.out.println("Child.tearDown"); } public void execute() { System.out.println("Child.execute - before"); inner(); System.out.println("Child.execute - after"); } } public class GrandChild extends Child { public void execute() { System.out.println("GrandChild.execute"); } }And the result would be the same. Inner can replace usage of super in constructor and destructors to control order of acquisition and release of resources, avoiding code conventions like always call super implementation before/after your code.