Info

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

OOP: Properties Containing Objects

2 Ansichten (letzte 30 Tage)
Leor Greenberger
Leor Greenberger am 12 Aug. 2013
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi All,
I defined a class called instr (which is short for instrument) that is derived from a handle class. The instr class sets up a remote connection to a specified instrument. I also created two other handle classes: source and state, so that you can interact with the instrument once you are connected to it. These classes are instantiated by the instr class in two separate properties.
I have a question about what to do next. I want to prevent access to the instr.source and instr.state objects unless you have successfully connected to the instrument. I have a property in the instr class that I can query to see whether I am connected or not. But based on http://www.mathworks.com/help/matlab/matlab_oop/properties-containing-objects.html , I am not sure how to prevent someone from doing, say, instr.state.TurnOnOutput, when the instrument isn't even connected. The only way I can think of is for every method in the source and state class to have a check whether you are connected, but this seems tedious.

Antworten (0)

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by