MATLAB Lazy Evaluation in Dependent Property

怎甘沉沦 提交于 2019-11-30 09:04:30

I assume you're using a value class. With a handle class (classdef myClass < handle), which is passed by reference, you can easily modify the class from within a get-method. For example, I use what you propose in order to load data from file (if not yet loaded) or from a private, hidden property.

Note that using a lazy dependent property the way you propose somewhat defeats the purpose of using a dependent property, i.e. the guarantee that your data is always up-to-date with the state of the properties it is derived from. Each time you change the other properties, your lazy property gets outdated.

You could (should) add a set-method to all other properties that sets the private property to empty (isempty(obj.myPrivateProperty) is the "logical flag" you need to know whether you have to calculate). But if you do that, why not just have the set-methods call some update method that updates/recalculates all "dependent" properties right away?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!