From: Scott H. <sc...@af...> - 2006-09-01 20:51:26
|
> 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? Yes, it does. > 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? Yeah, you can absolutely do something like this. In fact, you may notice that the first argument for most delegate methods is the "sender", which is the object that is requesting the delegated behaviour. Just do equality testing on that and have it behave appropriately. Scott |