Doens.be

  • Linkedin flickr twitter delicious Facebook Youtube

Tip for overriding methods

There is a simple and generic way to force overriding a method you created. To do so you just need create your new method and place a ‘throw error’ statement in it. To finish you can add the static method missingOverride from the error class and the funcName() to your error. Now when this method is called or the super() in you child class is called, you will get a error that you need to override your method.

public identifiername myMethod()
{
    throw  error(Error::missingOverride(funcName()));
}

When you use this peace of code you will get the following error:

Note: The error-class also has some other usefull static methods like: missingFormActiveBuffer, missingOverload, missingOverride, missingParameter, missingRecord and my favorite wrongUseOfFunction

Tags: , , , , ,

3 Responses to “Tip for overriding methods”

  1. April 20th, 2010 at 07:10

    Björn says:

    Why not use the abstract keyword (and abstract base class) if an implementation is required anyway? This makes the compiler check for missing methods and there’s no chance of errors at runtime.

  2. April 20th, 2010 at 08:30

    Jeroen Doens says:

    Forcing it with the keyword abstract is indeed a better way because of the check on compile time.
    Thx!

  3. April 21st, 2010 at 11:32

    Luegisdorf says:

    I think, the shown way with the exception throw is historically used in AX, when the abstract mofier was not active (AX 2.5).

Leave a Reply