Objective-C Best Practices – Is It Good to Have a Class with Several .h Files?

inheritanceinterfacesobjective c

I suppose the class have several different interfaces. Some it shows to some class, some it shows to other classes.

Are there any good reason for that?

One thing I can think of is with one .h per class, interface would either be public or private.

What about if I want some interface to be available to some friends' class and some interface to be truly public?

Sample:

@interface listNewController:BadgerStandardViewViewController <UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,NSFetchedResultsControllerDelegate,UIScrollViewDelegate,UIGestureRecognizerDelegate> {
}

@property (nonatomic) IBOutlet NSFetchedResultsController *FetchController;
@property (nonatomic) IBOutlet UITextField *searchBar1;
@property (nonatomic) IBOutlet UITableView *tableViewA;
+ (listNewController *) singleton; //For Easier Access
-(void)collapseAll;
-(void)TitleViewClicked:(TitleView *) theTitleView;
-(NSUInteger) countOfEachSection:(NSInteger)section;
@end

Many of those public properties and function are only ever called by just one other classes. I wonder why I need to make them available to many classes.

It's in Objective-c by the way

What do you mean? Interface is interface. In C++ you can declare some classes as "friends". In Objective-c you cannot I think. Basically I want to emulate that. My friends can access some members that's not available too publicly,.

Best Answer

I would say no. It is a sign that your class is too complex, or is trying to do too much. It may be that you want to split it into multiple classes, or that you want to rethink your abstractions completely.

One way would be to turn each "interface" into a class of its own, using the main class. You could export the "interface classes", but keep the main class more hidden. Not sure if it would buy you anything, though.