![]() |
Matlab代理类问题。 (关于:依赖属性)
考虑以下Matlab(2009a)类:
classdef BigDeal < handle properties hugeness = magic(2000); end methods function self = BigDeal() end end end classdef BigProxy < handle properties(Dependent) hugeness end properties(Access = private) bigDeal end methods function self = BigProxy(bigDeal) self.bigDeal = bigDeal; end function value = get.hugeness(self) value = self.bigDeal.hugeness; end end end 现在考虑对它们的以下用法: 设定: >> b = BigDeal b = BigDeal handle Properties: hugeness: [10x10 double] Methods, Events, Superclasses 单层: >> pb = BigProxy(b) pb = BigProxy handle Properties: hugeness: [10x10 double] Methods, Events, Superclasses 双层: >> ppb = BigProxy(pb) ppb = BigProxy handle with no properties. Methods, Events, Superclasses [B]问题:[/B]为什么我的双层代理在单层可以看到的时候看不到hugeness的空间?可以计算相关属性-但这是否由于某种原因仅深入了一层? [B]更新:[/B]请参阅以下我的答案以找到解决方法。 [B]回答:[/B] 这里的问题有两个: [LIST=1][*]所述BigProxy对象构造被设计成接受具有(非依赖型)的输入对象hugeness属性(如BigDeal对象),则其BigProxy对象可以访问然后来计算其自己的依赖于值hugeness属性。 [*]创建ppb ,您正在将BigProxy对象传递给BigProxy构造函数,您显然无法从另一个从属属性计算一个从属属性。例如,这是我尝试访问ppb.hugeness时引发的错误: ??? In class 'BigProxy', the get method for Dependent property 'hugeness' attempts to access the stored property value. Dependent properties don't store a value and can't be accessed from their get method. 换句话说,外BigProxy对象尝试来计算其依赖于值hugeness通过访问所存储的值属性hugeness用于内BigProxy对象,但不存在存储的值,因为它是一个[URL="http://www.mathworks.com/help/techdoc/matlab_oop/brh76wy-1.html#brh76wy-1_2"]依赖特性[/URL] 。 [/LIST]我认为针对这种情况的解决方法是让BigProxy构造函数检查其输入参数的类型,以确保它是BigDeal对象,否则抛出错误。 [url=https://stackoverflow.com/questions/5174667]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 04:59。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.