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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With