From: Ewan M. <mr...@mr...> - 2006-09-01 13:38:24
|
Hello, I'm trying to program my application using MVC pattern as described in Cocoa Fundamentals. "The delegate object itself is typically, but not necessarily, an object, often a custom object, that controls some part of the application (that is, a coordinating controller object)." CocoaFundamentals p148. Great so my thoughts so far I can either initialize my view objects with their controller e.g. var myView = (new MyView).initWithController((new MyController).init()); or as the text above suggests I can set it as a delegate and implement an informal protocol between the controller and view e.g. var myView = (new MyView()).init(); myView.setDelegate((new MyController).init)); From the actionstep source code there are three different ways to implement setDelegate in your Delegator It can be notified (see ASFieldEditor.as) It can be called directly and the delegate check to see that it conforms to informal protocol(see ASTreeView.as) It can be called directly but not checked to see if it responds to calls (see NSImage.as , when is m_delegate used?) You can create an interface if you want (ASFieldEditingProtocol.as) The naming strategy is either append Protocol or Delegate. Does this sound about right? So say I've got 10 small simple views shall I just bundle all my control code in one or two Controllers and set either as delegate for all the view? There doesn't seem much point spreading all the control code around by having parallel Views and Controllers. (i.e. one controller for each view). Cheers, Ewan |