I’m working on an NSWindowController, which is quickly starting to grow large. One of the nice things about the controller I’m working on, however, is that it’s fairly sectional – parts of it could be separated logically.
I would like to split this Controller into categories, to make it easier to find things. What is the general consensus regarding using a category for this purpose? Is there one? Are there examples of Apple actually using similar patterns?
This is a personal preference.
As an old time (1970s) programmer I like to keep any file to 1 page – in practice in Objective C My upper limit is 300-400 lines.
I have unfortunate memories of engineers writing monolithic FORTRAN programs full of spaghetti code.
There is no intrinsic benefit in limiting file size or using categories, but if it can make code easier to understand and maintain it is worthwhile.
I agree that if it is feasible to use classes this should be considered.
You should also consider whether using functions rather than methods could simplify the code – these can be put into a separate file.
I have used categories for both
NSWindowControllerandNSViewContorllerin one case reducing 2000 lines of code to 5 categories. This should have no impact on the resultant code, but certainly makes coding easier.You could look at Apple samples (and there are some examples of categories) but in the Frameworks there is no way to tell how the underlying code is written.
My recommendation is to limit file size by whatever means is convenient.