How can I separate the user interface from the business logic while still maintaining efficiency?

Posted by Uri on Programmers See other posts from Programmers or by Uri
Published on 2011-12-28T01:23:45Z Indexed on 2012/03/19 23:38 UTC
Read the original article Hit count: 341

Let's say that I want to show a form that represents 10 different objects on a combobox. For example, I want the user to pick one hamburguer from 10 different ones that contain tomatoes.

Since I want to separate UI and logic, I'd have to pass the form a string representation of the hamburguers in order to display them on the combobox. Otherwise, the UI would have to dig into the objects fields. Then the user would pick a hamburguer from the combobox, and submit it back to the controller. Now the controller would have to find again said hamburguer based on the string representation used by the form (maybe an ID?).

Isn't that incredibly inefficient? You already had the objects you wanted to pick one from. If you submited to the form the whole objects, and then returned a specific object, you wouldn't have to refind it later on since the form already returned a reference to that object.

Moreover, if I'm wrong and you actually should send the whole object to the form, how can I isolate UI from logic?

© Programmers or respective owner

Related posts about design

Related posts about architecture