Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to derive a subclass that is a "frozen" state of another class?

1 次查看(过去 30 天)
Suppose dynClass has lots of dependent properties calculated on the fly and/or read from private properties, based on complicated state-change-rules. I would like a statClass derived from dynClass that is essentially a snapshot of the current state of dynclass. For property values it is simple to give dynClass a to_struct() public method. But I want to call some public and protected methods of dynClass on statClass, including perhaps future ones.
Sounds easy? But what if I want to minimize changes in the complicated, legacy dynClass? I'm afraid of breaking something if I start moving too many things there! statClass however can be written from scratch.
Is this possible?
  1 个评论
Naor Movshovitz
Naor Movshovitz 2017-6-26
Something I already tried and failed is redefining the set/get methods of the dependent properties of dynClass in statClass. It this were allowed then for each dependent property dp of dynClass I could implement a private property real_dp in statClass and redefine get.dp of statClass to refer to it.
Unfortunately this is not allowed in matlab. I would have to modify get.dp inside dybClass as well and have it call a protected method. This is a lot of boilerplate code. Is there a better solution?

回答(0 个)

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by