Could private values that we like to edit and save through getters and setters be in a public variable class rather than being private. Direct access to the actual float could still be private to the class through a friend connection. Then we could access the values with class getter and setter or directly, but still with encapsulation. This would make it very easy to link layouts to ValueTrees, to add lambda for listeners etc.
I’m not sure if I understood that right, juce::var is one scalar variable, that can have different types (by aggregation rather than polymorphism).
Note that both, var and DynamicObject are not designed to be inherited, so protected would be meaningless in this case.
Hope that explains it a bit
I was more pondering an alternate form of encapsulation using a public friend class to wrap the private variable, share it privately with the friend class and yet allow it to code as if it were public elsewhere where it still follows encapsulation principles. I chose var because it already exists.
I have been reworking my plugin so that everything loads dynamically from an editable xml document. The current encapsulation locks me out of many otherwise simple, yet on mass solutions. Just to save a plugin window size is a great example.
No worries, helps me sometimes to get a fresh perspective…
In terms of ValueTree, there is a handy method, ValueTree::getPropertyAsValue(). This Value can be used to connect to UI elements, e.g. by getting a Slider’s value object and calling referTo (otherValue) on that, so they will be linked/updated. No polymorphism needed here.
For your plugin window size, I think it is best to simply update/apply that in your ValueTree in getStateInformation/setStateInformation, since that is the only place where this can be changed apart from being dragged.
Hope that helps
Thanks for that info