Borrar filtros
Borrar filtros

Pass data to an instance of a class outside the constructor

1 visualización (últimos 30 días)
Anon
Anon el 11 de Jul. de 2012
Dear all,
I am currently working on a class that is associated with various methods. One of the methods (function) produces some additional data associated with the instance of the class. This data should be available if I call the function with the same instance again, but it should not be available (since it eats memory) if I have never called that function. Can anybody give a hint, how I could pass this data to the instance without that it was generated in the constructor?
Hope I made myself clear. I am still new to OOP and not too familiar with the terminology.
Best regards, Anon

Respuestas (1)

Sean de Wolski
Sean de Wolski el 11 de Jul. de 2012
obj = object_of_some_class(pi,exp(1));
obj.some_property = that_value; %set that other property here
  7 comentarios
Sean de Wolski
Sean de Wolski el 13 de Jul. de 2012
Then make it a handle class! This is exactly the reason for handle classes, i.e: you pass the handle to the object around and allow other functions to modify it via its handle.
Anon
Anon el 13 de Jul. de 2012
I see, there is still a lot to learn. A quick reading of the difference of handle and value classes reveals that handle classes might be an elegant solution to my problem. Thanks for your help!

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by