Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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,.

share|improve this question
    
Are these interfaces actually distinct classes? –  Winston Ewert Jun 3 '12 at 4:03
1  
I'd shy back from it solely for the headache ABI compatibility would (AFAIK) be... I'm not an expert though, maybe I'm being paranoid. –  delnan Jun 3 '12 at 4:07
    
So you are telling us you have already two header files with different interface definitions for the same class (I cannot see this in your example, but that is what you are describing in your question)? Does that work in Objective-C? In C++ this would not be possible. –  Doc Brown Jun 3 '12 at 13:18
    
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,. –  Jim Thio Jun 3 '12 at 16:19

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
Which mean the original class will have interface only to the interface classes. So we got back to original problem. –  Jim Thio Jun 4 '12 at 3:38

Typically you want one .h file per class. This helps to encapsulate all of the related info for a class in one place. Personally I have never run into multiple .h files for a single class, though I have often run into multiple classes in a single .h file.

Ultimately it comes down to whether or not others will need to work with your code. If so I recommend staying with a single .h file per class. If no one else will ever see your code then do what makes sense to you. Just keep in mind that bad habits can be hard to break.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.