An abstract class is a normal Lisp class without an associated Objective-C class. As well as defining named Objective-C classes, define-objc-class can be used to define abstract classes by omitting the
:objc-class-name
class option.
The main purpose of abstract classes is to simulate multiple inheritance (Objective-C only supports single inheritance): when a Lisp class inherits from an abstract class, all the methods defined in the abstract class become methods in the inheriting class.
For example, the method
"size"
exists in both the Objective-C classes
MyData
and
MyOtherData
because the Lisp classes inherit it from the abstract class
my-size-mixin
, even though there is no common Objective-C ancestor class:
(define-objc-class my-size-mixin ()
())
(define-objc-method ("size" (:unsigned :int))
((self my-size-mixin))
42)
(define-objc-class my-data (my-size-mixin)
()
(:objc-class-name "MyData"))
(define-objc-class my-other-data (my-size-mixin)
()
(:objc-class-name "MyOtherData"))