This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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 Comment
Naor Movshovitz
Naor Movshovitz on 26 Jun 2017
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?

Answers (0)

Community Treasure Hunt

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

Start Hunting!