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: Best Practice, Class, Dynamics AX, Error, Tips & Tricks, X++
This entry was posted on Monday, April 19th, 2010 at 06:00 and is filed under Dynamics AX. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


April 20th, 2010 at 07:10
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.
April 20th, 2010 at 08:30
Forcing it with the keyword abstract is indeed a better way because of the check on compile time.
Thx!
April 21st, 2010 at 11:32
I think, the shown way with the exception throw is historically used in AX, when the abstract mofier was not active (AX 2.5).