Re: [iPhone-AppDev-Auditors] Digest for iphone-appdev-auditors@googlegroups.com - 1 Message in 1 Topic

26 views
Skip to first unread message

Cris Sagastume

unread,
Jul 26, 2012, 3:19:55 PM7/26/12
to iphone-appd...@googlegroups.com
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, <iphone-appd...@googlegroups.com> wrote:

Group: http://groups.google.com/group/iphone-appdev-auditors/topics

    Zhisheng Huang <lorix...@gmail.com> 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
    methods.
     
    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,
     
    -Zhi

     

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 iphone-appd...@googlegroups.com.
To unsubscribe from this group, send email to iphone-appdev-aud...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphone-appdev-auditors?hl=en.



--
- Cris

Mark Beaty

unread,
Jul 26, 2012, 3:55:34 PM7/26/12
to iphone-appd...@googlegroups.com
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.

zhuang

unread,
Jul 26, 2012, 5:55:15 PM7/26/12
to iphone-appd...@googlegroups.com
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,

-Zhi



--


Reply all
Reply to author
Forward
0 new messages