Best practice with class/GUI

3 次查看(过去 30 天)
Hi all, I've got a GUI based on a class I've developped. I've got a property which can be modified either directly (if the GUI is not called) or via the GUI, and I'm wondering what is the best practice to make sure that what is stored in the property is the same value that displayed by the GUI. I've done it by a set method (which looks for the corresponding edit box in the GUI if it exists) and with a listener which update the numbers if something changes... But I'm not sure which one is the best practice or if there is a better solution.
Thanks
Stéphane

采纳的回答

Adam
Adam 2016-2-8
I would generally use the GUI component callback in my class to update the class property or I would use a dependent property whose get function queries the UI, but the latter only if it always has the UI.
In the other direction then I would do as you say and add a PostSet listener to the property and in its callback update the UI from the property.
Obviously if the GUI component is optional these bits of functionality would need to be wrapped in if statements to ensure the GUI component is there first. In the first case this is no problem as the callback would not exist without the UI and in the second case a simple check for the UI or the specific component before writing to it would work fine.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Events 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by