MATLAB Answers

Cedric Wannaz
2

Dynamic superclass name in call to superclass method.

Cedric Wannaz
さんによって質問されました 2017 年 12 月 5 日
最新アクティビティ Cedric Wannaz
さんによって 編集されました 2017 年 12 月 5 日
Dear all,
but back then the only option seemed to involve the evil eval:
eval( ['methodName@', superclassName, '(args..)'] ) ;
Do you know if MATLAB implements a better mechanism now?
To give a little more information about the context, I am working on a framework that involves e.g. the following classes:
Project < ProjectKernel < Resource < ResourceKernel < Core < handle
each of which implements an errorManager method that produces extended error analysis/reporting. Now say the Core implements a method/validator for setting a user level : Core.set.userLevelId. If I try to set an invalid user level in a project object:
project = Project() ;
project.userLevelId = -1 ;
the error management mechanism makes Project.errorManager capture the error, which must delegate the creation of the error report to Core.errorManager (because each class implements the management of errors associated with its own specific features/resources). The class name Core can easily be extracted from dbstack, but right now it seems that the only way to call errorManager@Core(...) is by using the approach based on eval.
Of course, it would be more satisfactory to use nested try/catch statements and to filter/rethrow based on the identifier, but we are not in such a context with the hierarchy of classes.
Thanks,
Cedric

  0 件のコメント

サインイン to comment.

0 件の回答


Translated by