Amazon.com Widgets why class extension?
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 30, 2014, 11:57:55 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Programming in Objective-C, 4th edition
| |-+ Chapter 11
| | |-+ why class extension?
Pages: [1] Go Down
Print
Author Topic: why class extension? (Read 1004 times)
m.sniper
Newbie
*
Posts: 5






on: March 03, 2012, 10:17:34 AM

After reading the class extension section, I am very confused of how it benefits the programmer.

I do understand categories, e.g. if I need to add some extra methods to the system class, instead of modifying the system source code I can simply define a new category.

But I just don't see why we need class extensions. One of the requirements of using the class extensions is to define the
@interface existingClass()
-(void) newMethod;
...
@end

and

@implementation existingClass
-(void) newMethod {
...
}
@end

in the main implementation instead of a separate implementation. If so then why don't we just simply change the existingClass.h and .m??

Logged
m.sniper
Newbie
*
Posts: 5






Reply #1 on: March 03, 2012, 10:28:16 AM

nevermind, I missed a paragraph. here is the explanation:

Quote
Unnamed categories are useful because their methods are private. So if you need to write a class that has data and methods that can only be used within the class itself, an unnamed category might just fit the bill.
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

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 (c) 2009 classroomM.com. All rights reserved.