Should all, none, or some overriden methods call Super?

Posted by JoJo on Programmers See other posts from Programmers or by JoJo
Published on 2011-06-24T20:45:45Z Indexed on 2011/06/25 0:32 UTC
Read the original article Hit count: 285

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?

© Programmers or respective owner

Related posts about best-practices

Related posts about object-oriented