Set/Get/Set/Get
Posted May 17th, 2003 @ 08:39pm by Erik J. Barzeski
I continued working on the core UI for MailDrop 2.0 today. I added outlets to some more checkboxes and text fields and made them undoable. With a strong MVC background, "undo" is a fairly easy but - repeat after me - T E D I O U S task. I have about fourteen thousand lines of code (well, okay, about 500) of pure getter/setter/UI-updater code.
Because we want to be very, very AppleScriptable in the end, I'm clinging to MVC as if it was a hot babe and I was Rob Cesternino. What's funny is that I noticed that, upon entering a string in a text field, the following occurs:
- The action of a text field is
setSomeValue:
(generic name used here), a "setter" of sorts. - A string comparison takes place so that you can't add infinite instances of the same string to the undo stack. This calls a
value
"get" accessor in the model to check the current string and compare it to the UI string (the one just entered). - The
setSomeValue:
calls asetValue:
method in my model. - The model posts a notification to the window to update its UI.
- The window "updateUI" method calls the same
value
"get" method in the model to make sure it sets the text field to the proper value.
Overkill? Actually, no. Amusing? Undoubtedly. But again: T E D I O U S. 🙂
Posted 17 May 2003 at 10:08pm #
Weekend Edition: WarCraft, Cocoa, Exams
Today I played in the WarCraft 3 tournament. It was Humans & Orcs on Two Rivers, one of the new maps. I have to say I like the map, but it has some flaws. For one thing, it felt like...
Posted 17 May 2003 at 10:40pm #
This is why people get into code generation 🙂
Presumably you have some sort of object model that you are creating all your get/setters for? Could you describe that object model as an XML document? You could then run an XSLT transform to convert that into all your code. You could delgate most of the work to an abstract base class. It sounds like you may be kinda there, having setSomeValue call setValue with 'Some' as a method parameter?
Posted 17 May 2003 at 11:56pm #
All of that work seems like more work than just copying/pasting similar chunks of code and changing a name or two here and there. I haven't got time to learn XSLT too.
Posted 23 Jun 2003 at 10:07pm #
Like my other comment, this is the same answer: EOF. Makes all that stuff go away.