Should all, none, or some overriden methods call Super?
- by JoJo
When designing a class, how do you decide when all overridden methods should call super or when none of the overridden methods should call super? Also, is it considered bad practice if your code logic requires a mixture of supered and non-supered methods like the Javascript example below?
ChildClass = new Class.create(ParentClass,
{
/**
* @Override
*/
initialize: function($super) {
$super();
this.foo = 99;
},
/**
* @Override
*/
methodOne: function($super) {
$super();
this.foo++;
},
/**
* @Override
*/
methodTwo: function($super) {
this.foo--;
}
});
After delving into the iPhone and Android SDKs, I noticed that super must be called on every overridden method, or else the program will crash because something wouldn't get initialized. When deriving from a template/delegate, none of the methods are supered (obviously). So what exactly are these "je ne sais quoi" qualities that determine whether a all, none, or some overriden methods should call super?