5 ms·
Many GUI programs use components to store data instead of using them only for display, but this eventually means that your program's state is contained in lots
by BubRoss 7y ago
Many GUI programs use components to store data instead of using them only for display, but this eventually means that your program's state is contained in lots of different data structures with different ways of accessing them. Having everything centralized yet organized enables managing a lot more complexity.
- Udik 7y agoI don't understand, it seems you could say the exact same about object oriented programming in general. But encapsulation is a feature- it allows you to expose to the rest of the application only the data that really needs to be exposed, through a well defined interface. It allows to compose applications of parts that are completely self-contained, without having to think of their interaction with the entire application. I get that in some cases you might need components to plug into a global state that can have multiple sources of change, but this is more an exception than the norm.
- BubRoss 7y agoThis might the conventional wisdom, but the reality is that in a single thread, hiding data behind all sorts of obstacles is a huge detriment. If you can already get to it, you might as well be organized so you can get to it easily. 'object oriented programming' (whatever it means exactly) is good for creating interfaces to data. The GUI might need an interface to its data, but the state of whatever is being processed and manipulated is less likely to need a special interface and almost definitely not whatever a component meant to display data provides. If you 'encapsulate' every tiny bit of information inside GUI components you end up with things like storing a string in a GUI label or storing a list in a list selection component. Then every time you want to access that information you have to extract it from the GUI, possibly keeping in mind the lifetime of the UI components.