MATLAB Answers

Dynamic superclass name in call to superclass method.

6 ビュー (過去 30 日間)
Cedric Wannaz
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.

  0 件のコメント

Sign in to comment.

回答 (0 件)

Translated by