1
votes

I've always used Objective-C in a very sterile, textbook situation, which is to have a single class defined within a single file, and having a set of files, one for implementation, and one for interface.

I'm ready to start traveling into the less preferable, but quick-and-dirty means to build classes, declaring and using multiple classes within a single implementation file. (EDIT) I don't plan to do this in production code, just to test some ideas quickly off to the side if you will, but still able to access the data in the full application, rather than creating a separate sandboxed XCode Project to do it, which would not have access to all the data I'll need to test my idea.

All the educational material I can find only demonstrates the sterile method of one .h and one .m file and a single interface and implementation.

So say I want to have ClassA, ClassB, and ClassC all defined in ClassA's implementation file. Do I still need to declare an interface for ClassB and ClassC and in what order in ClassA can I declare all this stuff and have it work properly.

Thanks a lot.

1

1 Answers

3
votes

Yes, you have to declare the same things. You should declare the Interfaces prior to the Implementations.

But I suggest that this not be done to save time and only if there is a close relationship. An example would be other languages that allows sub-classes, in Objective-C this might be a candidate for a second class in the same file. I would expect only not class in the header file.

I restrict this to classes that are only used by the main class in the file and only the main class's Interface is in the header file. The second class would be a helper class to the main class. This is certainly better than just letting a class grow beyond a single responsibility.