When I create a protocol, I was used to put it right into the .h from a class that this protocol belongs to. But what when I want a pretty "general" protocol that a lot of classes might use? Would I make a .h file for this protocol only? And if so, are there special naming conventions to distinguish it from a class header file?
views:
43answers:
3
+2
A:
Yes if it's a general thing that will be shared, put it in its own .h file. As for naming, just use the standard TypeName case for the protocol, and typename.h for the file, like you would for other types and classes.
Mike Weller
2009-12-14 12:00:58
+3
A:
I think whatever is the clearest, most obvious way of doing it is the "right" way. In the case you describe having the protocol in its own header file probably does make sense.
There's no generally accepted naming convention for protocols so, again, call it something that makes sense.
Stephen Darlington
2009-12-14 12:15:15
+2
A:
For avoiding name collision, as would occur with NSObject
class and protocol, I name the header file of a protocol with the Protocol
suffix:
- class:
OWNWhatever.h
- protocol:
OWNWhateverProtocol.h
But if you plan to use your protocol with several classes, such name collision is not likely to happen.
mouviciel
2009-12-14 12:21:06