开发者

Sheet and WindowController Delegates - Is this a good approach?

I'm using a sheet to ask the user some information for an operation that the application performs. The sheet has some 10 to 15 options (split into 4 tabs, so its a relatively clean UI) that the rest of the program needs to know before proceeding.

Right now, I have a separate window controller class for the sheet called SheetController. SheetController has a delegate proper开发者_Python百科ty and the main controller, AppController, is set as the delegate.

When the user clicks OK in the sheet the delegate is notified and a method called didClickDone:(id)sender withParameters:(id)parameters is executed. parameter is a object that contains various properties from the sheet. My question is, is this a good approach to handling Sheets and returning data from them?

Secondly, one thing that bothers me is that the parameter is just a dead object - it only has accessor methods. It doesn't do any manipulation on them as its entire purpose is to 'carry' the data to the main controller, which in turn passes the information to the Model of the program. And, unless I'm missing something, shouldn't I just declare parameter to be a normal C struct? Or is there an advantage of using an object for this sort of purpose?

EDIT: Would a passing an NSDictionary be a good compromise? I could save the returned information with their keys in the dictionary and simply pass it.


Maybe I would not notify directly the controller from the push button event handler but call another routine that encapsualates the logic on how the data have to be commited to the model.

Don't worry about the empty object. Is a common pattern to use it and is called DataTransferObject

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜