Re: Controller layer and application design
Re: Controller layer and application design
- Subject: Re: Controller layer and application design
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 17 Dec 2003 01:25:15 -0800
On Dec 16, 2003, at 9:35 PM, Bill So wrote:
i.e.: Create a new object using the values entered in text views. The
new object is then added into the NSArrayController.
I have 2 ideas to solve this problem:
Method 1: subclass NSArrayController. Add outlets that connect to the
text fields. Add new object when subclassed NSArrayController detects
changes in the text fields.
Method 2: use a NSObjectController in addition to the
NSArrayController. The NSObjectController is used to bind to the text
fields. The NSObjectController passes messages to NSArrayController
to add new data source object.
Method 1 doesn't use key-value bindings for text fields. But method 2
does.
What's your opinion?
Firstly, there's no sin in using Target/Action in an app that also uses
Cocoa Bindings. :-) Use whichever makes life easier for you.
In Method 1, however, I'm not sure that you'd want to "detect changes
in the text fields"? I suspect it would still be more natural to
supply an "Add" button? The controller could then use the values in
the text fields to set values in the new object.
Method 2 seems reasonable enough. It would have to manage an object,
and presumably pass a *copy* to the array controller on Add. This
design benefits from flexibility -- useful if your object model is
still volatile -- since it may be easier to modify bindings in the UI
than to set up new outlets etc. There should also be less code to
write, but it feels a little "fiddly", almost like cheating :-) It
also seems to suffer a problem where values are not updated properly
(at least in this late night implementation:
<
http://homepage.mac.com/mmalc/CocoaExamples/Method2.zip>
)
Perhaps a "compromise": Method 3 :-)
A variant on Method 1, where the array controller has a mutable
dictionary instance variable which serves as a temporary placeholder
for values for new object. The dictionary is bound to the text fields
with keys the same as the keys for the new object. These are set in
the controller's newObject method using setValuesForKeysWithDictionary:
-- see:
<
http://homepage.mac.com/mmalc/CocoaExamples/Method3.zip>
This gives a compact design, whilst still retaining flexibility.
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.