Re: Regarding MVC design pattern
Re: Regarding MVC design pattern
- Subject: Re: Regarding MVC design pattern
- From: Dave Keck <email@hidden>
- Date: Thu, 20 May 2010 05:27:25 -1000
> I'll give you a concrete example. We have an NSController-like class that
> lives in a framework. Its designated intializer is -initWithContent:. In one
> of our apps, we have a subclass of this whose initializer is
> -initWithDocument:, and which uses the document to figure out its content.
> It also overrides -setContent: to register for notifications and the like.
> -setContent: relies on certain state that is set up in -initWithDocument:,
> but this setup can't be done until -initWithDocument: calls -[super
> initWithContent:]. But that method uses the -setContent: setter to set its
> content property. Boom!
Which could be solved with a simple if-statement within the subclass'
-setContent:, allowing you to use accessors everywhere to avoid code
duplication and giving your subclasses full control over the setting
of the content property.
This issue is highly debated to the point that it is merely a question
of style. Mike Ash has an excellent article on the topic here:
http://www.mikeash.com/pyblog/friday-qa-2009-11-27-using-accessors-in-init-and-dealloc.html
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden