Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C class definition confusion

I'm learning Objective-C through Cocoa (And loving it). I'm following a tutorial. Theres a class called Menu and the interface looks something like this.

@interface Menu: MenuObject {}
@end

@interface MenuLayer : LayerObject {}
-(void) someMethod:(id)sender
-(void) someOtherMethod:(id)sender
@end

and the implementations follow the same convention

@implementation Menu
    -(id)init{
        // blah blah blah
    }
@end

@implementation MenuLayer
    // init, someMethod and someOtherMethod stuff here
@end

Which to me looks like two separate object/classes being defined and implemented in the same files. Is there a reason for doing this? Would the result be the same if I split the .h and .m files up into Menu.h/.m and MenuLayer.h/.m ? Or am I misunderstanding something fundamental?

like image 422
gargantuan Avatar asked Mar 27 '09 13:03

gargantuan


1 Answers

It should be fine if you split those into separate files. Most of the time when you see things implemented that way it's just because the 2 classes are so tightly coupled together that you would really never use one without the other.

So, it's really just a style thing. There's no "magic" to the fact that they are both defined and implemented in the same file.

like image 195
Eric Petroelje Avatar answered Oct 06 '22 00:10

Eric Petroelje