Is it a good idea to set viewController subclass code to multiple files?

I made a great program. This is the type of header I used:

@interface:BGDetailBusinessViewController<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIScrollViewDelegate,BGDetailFooterViewProtocol,BGDetailPhotoCell,PageControlDelegate,UINavigationControllerDelegate,UIActionSheetDelegate,BGShareSocialDelegate,BGReviewControllerProtocol> 

I think the code is smell. This single BGDetailBusinessViewController.m file BGDetailBusinessViewController.m responsible for handling too many things.

What is the normal pattern for odor removal?

Is there any open source code sample of large Objective-C codes? Thus, we can all see how a professional works when they make a really really really really big program.

+4
source share
1 answer

You are right - in the model controller (MVC) template, the controller job should act like a glue between the model and the view. Therefore, it should not contain a lot of code, and the code that it contains is responsible for the mediation between the view and the model.

If you use an interface builder, it can be easy to get a lot of code in your controller. This can be avoided, but my suggestion is to use code representations for more complex work.

  • These views should use composition — look for reusable collections of user interface elements and create them as discrete classes. Create your ideas from them.
  • Create your own delegate protocols to transfer data between your views and the model. Typically, the controller will be a specific implementation of the delegate, but if this is of great concern, you can use a separate class and provide this as a member of the view controller (dependency injection).
  • Use Object Orientation to create a rich model.
  • If it really makes sense to have one large class, encapsulate related parts using categories.

In your particular case, why not have a representation of both the UITableViewDelegate and the data source, simply providing a method to pass the necessary data to it? This will be more true for the MVC design pattern.

+3
source

All Articles