检查和编辑对象的私有/受保护属性
在 MATLAB 2011b 中,我有一些类具有许多私有或受保护的类属性。这是设计使然,因为我不希望这些除了我的类自己的 getter/setter 之外的任何东西都可以查看、可读、可写等。
然而,在开发过程中有时我想看看这些属性的状态。类对象可在工作区中检查,但是当我通过双击工作区中的对象访问变量编辑器工具时,所有私有/受保护的属性都不可见。
我可以理解这可能是设计使然,但我希望有一个我缺少的设置可以让我查看它们。
In MATLAB 2011b, I have some classes that have a number of private or protected class properties. This is by design, as I do not want these to be viewable, readable, writable, etc. by anything other than my class's own getters/setters.
However, there are times during development when I want to see what the state of these properties are. The class object is available to inspect in the workspace, but when I access the Variable Editor tool by double-clicking the object in the Workspace, none of the private/protected properties are visible.
I can understand that this is probably by design, but I'm hoping there is a setting I'm missing that will let me view them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不想修改属性以进行调试,则可以使用调试器来检查私有/受保护的变量。为了方便起见,您甚至可以编写一个进入调试器的方法,这样您就不必手动设置停止:
如果您调用
to = testObj_debug, to.checkProps
,您正在访问调试模式,其中隐藏属性p1
是可访问和检查的。If you don't want to modify the attributes for debugging, then you can instead use the debugger to inspect the private/protected variables. For convenience, you can even write a method that gets you into the debugger, so that you don't have to manually set a stop:
If you call
to = testObj_debug, to.checkProps
, you are accessing the debug mode, in which the hidden propertyp1
is accessible and inspectable.