Re: [iPhone-AppDev-Auditors] Digest for - 1 Message in 1 Topic

Skip to first unread message

Cris Sagastume

Jul 26, 2012, 3:19:55 PM7/26/12
If you create a super class, that contains the same implementations, then have these classes subclass that super class, then they'll just inherit the super's implementation. That means that your classes have to be similar enough that they derive from a common class.

On Tue, Jul 24, 2012 at 12:10 AM, <> wrote:


    Zhisheng Huang <> Jul 23 04:38PM -0400  

    Hi folks,
    I am not sure if this is an appropriate place to ask a general objective C
    question, but i want to give a try anyway.
    So there is this project I am working on, a couple of customed
    UIViewControllers(e.g. Controller1, Controller2, Controller3). They all
    confirm to a delegate and have impementations for all the required delegate
    My question is: I know that for Controller1, Controller2 and Controller3,
    all those implementation for the delegate methods are the same, how can I
    abscact it and re-use all this same codes into one place? Maybe use another
    class(DelegateClass) as a member variable inside those UIViewControllers?
    Again, thanks for your time and patience for taking a look at my question.
    Best regards,


You received this message because you are subscribed to the Google Group iphone-appdev-auditors.
You can post via email.
To unsubscribe from this group, send an empty message.
For more options, visit this group.

You received this message because you are subscribed to the Google Groups "iPhone Application Development Auditors" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

- Cris

Mark Beaty

Jul 26, 2012, 3:55:34 PM7/26/12
Zhi, I think you're on the right track. Prefer composition over inheritance in situations like this. It will make your life easier, especially when it comes to testing your code. Also, consider whether this common code you are trying to factor out is common for a good reason, or whether it's just by happenstance. Is there the possibility that one Controller may need to handle something differently in those delegate methods down the road? Either way, change will be easier to deal with if you use composition instead of inheritance in this situation.


Jul 26, 2012, 5:55:15 PM7/26/12
Thanks Mark and Cris's reply!

I agree with your mark's analysis and concerns, the major reason that inheritence is not an ideal solution is that those concrete subclasses have no choice to inherite from other classes than the one created by ourselves.

Although the strategy that favor composite over inheritence is good, I havn't figure out to create another class to handle the delegate method implementations. 

Category is also another way to solve this problem, i could put the same delegate methods into the category for a parent class such as UIViewController. 

Another question is, do you know any good book for design patterns for iOS/Cocoa platform? which also useful for iOS 5?

I found <Cocoa Design Pattern> but it was published in 2009, not sure whether it fits our latest iOS5/6 ARC, stroryboard platform.

I also found  <iOS 5 Programming Pushing the Limits: Developing Extraordinary Mobile Apps for Apple iPhone, iPad, and iPod Touch>

Anyone read it as well ?

Best regards,



Reply all
Reply to author
0 new messages