Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
Naor Movshovitz
Naor Movshovitz am 26 Jun. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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 Kommentar
Naor Movshovitz
Naor Movshovitz am 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?

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by