Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

2 visualizaciones (últimos 30 días)
Naor Movshovitz
Naor Movshovitz el 26 de Jun. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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 comentario
Naor Movshovitz
Naor Movshovitz el 26 de Jun. de 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?

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by