Extract superclass
The Extract Superclass refactoring enables extracting certain members of a class into a newly created superclass.
Extract a superclass
Select the desired class in the editor.
Select
from the main or context menu.In the dialog that opens, type the name of the new superclass and select the members that you want to move to the superclass.
Click Extract.
Code examples
Before | After |
---|---|
// All methods of the Dog class
// will be moved to a superclass
// Dog.h
@interface Dog : NSObject
- (void)run;
- (void)eat;
@end
// Dog.m
@implementation Dog {
}
-(void)run {
NSLog(@"I am running");
}
- (void)eat {
NSLog(@"I am eating");
}
@end
|
// New superclass
// 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
// The Dog class is now a subclass
// of the Animal class
// Dog.h
@interface Dog : Animal
@end
// Dog.m
@implementation Dog {
}
@end
|
Last modified: 26 August 2021