Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
December 10, 2018, 03:24:07 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Where to put categories?  (Read 2340 times)
purplebox
Newbie
*
Posts: 12



WWW
« on: September 01, 2009, 04:08:59 AM »

In the section about categories it is explained that:
Quote
It also gives you an easy way to extend an existing class definition without even having access to the original source code for the class and without having to create a subclass.

So there are cases that I can't put it in the original class. I also don't want to clutter my main.m file. Where then do I put that @interface and @implementation code of my category?

If I create a new file and put the category code in there, it effectively is a new class, isn't it?

Please, illuminate me Obi-Wan...
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #1 on: September 01, 2009, 09:05:25 AM »

You can put it in the original class files if you want.  You can put the category into separate .h and .m files.  If you are working on a large project, for example, this allows you to divide the work of implementing a class and methods among several programmers.   Also, by restricting access to the category's .m file (where the code is), you can in a sense create "private" methods.

Remember that a category is an extension of the original class; it shares its instance variables and methods.  So that is quite different from defining a new class.

Cheers,

Steve Kochan
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.