Extract subclass
The Extract Subclass refactoring enables extracting certain members of a class into a newly created subclass.
Perform the Extract Subclass refactoring
Select the desired class it in the editor.
Select
from the main or context menu.In the dialog that opens, type the name of the new subclass, select the members that you want to move there, and click Extract.
Code example
Before | After |
---|---|
// Animal.h
@interface Animal : NSObject
- (void)meow;
- (void)run;
- (void)eat;
@end
// Animal.m
@implementation Animal {
}
// This method will be moved
// to a subclass
- (void)meow{
NSLog(@"Meow!");
}
- (void)run {
NSLog(@"I am running");
}
- (void)eat {
NSLog(@"I am eating");
}
@end
|
// New subclass
// Cat.h
@interface Cat : Animal
- (void)meow;
@end
// Cat.m
@implementation Cat {
}
- (void)meow{
NSLog(@"Meow!");
}
@end
// The Animal class
// Animal.h
@interface Animal : NSObject
- (void)run;
- (void)eat;
@end
// Animal.m
@implementation Animal {
}
- (void)run {
NSLog(@"I am running");
}
- (void)eat {
NSLog(@"I am eating");
}
@end
|
Last modified: 26 August 2021