Thursday, March 25, 2010

Get your UI out of my logic

I really don't like seeing something like this used in a domain object.

I've also seen a list of objects retrieved from the database and put into an Object array with "Select" as array[0] and the rest of the objects being actual objects someone might care about. Let's just have everyone remember what type of objects are in this array, and they should also remember that the first element isn't one of those!

I can't imagine what people find so hard about producing a new list or whatever to base their combo box model on at the time that the combo box is actually created. Furthermore, with something like the enum above, the enum constants use lowercase letters because it'll look nicer when they're rendered in the UI using the default toString(). The use of toString() to produce the text for the UI in general bothers me. I want it to produce text that's helpful to me in error messages... use some other means for rendering it to users.

I guess what I want to say is: keep user interface concerns where they belong, near the user interface!