There are no abstract classes, but you can create something similar using a combination of class and protocol (which is similar to the Java interface). First, divide your abstract class into those methods that you want to provide default implementations, and those that you need to implement subclasses. Now declare the default methods in @interface and implement them in @implementation and declare the necessary methods in @protocol . Finally, you get subclasses from class<protocol> - a class that implements the protocol. For instance:
@interface MyAbstract - (void) methodWithDefaultImplementation; @end @protocol MyAbstract - (void) methodSubclassMustImplement; @end @implementation MyAbstract - (void) methodWithDefaultImplementation { ... } @end @interface MyConcreteClass: MyAbstract<MyAbstract> ... @end @implementation MyConcreteClass
If you are worried about using the same name for the class and looking at the protocol in Cocoa, where NSObject follows this pattern ...
NTN
source share