I had a debate with a friend and I'd likeI'm looking for a way to hear how can we resolve it and decide which approach is better for maintenance in the long run and whether there's some consensus about a best practice regarding it:
If an application shows some data on the UI (for example order ids that some come from input thatare added dynamically by the user is currently inserting) and there's a button which suppose to do some action with that data shown on the ui (e.g. send those ids to processing) - how should the data be fetched:
Is it better that the code handling the button click take the values directly from the UI by accessing the UI element?
After all, UI changes the most often, so if I take the data from the UI it's more likely that the button click handling code will also have to be updated because how it consume the data from the UI might get broken.
Or should the data be taken from some variable that will save the state?
But if I add a special variable just to save the state, I add a new place in code that have to be maintained on changes and that artificial state variable might not be 100% synchronized with the UI and cause bugs.
How to decide which approach to choose? Is adding a special variable just to save state considered a code smell?