Plaster

text
The OO model of CL by placing responsibility for any encapsulation of a class separate from the class definition introduces issues not common in most "popular" languages when a child class is not in the same package as the parent. Given a defclass in a package say :PkgA (users of class not in that package say in :PkgC) 1. To expose (i.e. make "public") an object from a package you need to: Export the symbols for the class any slot reader, writer or accessor any methods / generic functions 2. Any symbol for a class/slot/method/gf not exported affectively are "private" but available to the entire package not just class methods 3. Any child classes not in the same package say :PkbB it is necessary to :import-from package any exported class/slot/method/gf of the parent that will be available for use and/or exported on the child class Export the symbols as in 1 above for any class/slot/method/gf on wishes to make public 4. Any symbol that is not exported a second time in the new packages exports is now "protected" for use in the child class's package but not available to users of that package :PkbB 5. Summary - complete symbols for (including the parent class's) slot/method/gf and the class symbol needs to be exported, ie you define the full public interface of the class in the exports for each child class in its own package and need to use/import-from the parent class's paclage Alternatively You keep the entire interface/protocol for parent and children in one package and use that interface/protocol package and implement in separate packages. example: (defpackage #:tpac (:use #:cl) (:export :myclass ; class :myslot ; accessor :set-myslot ; method)) (in-package :tpac) (defclass myclass () ((myslot :accessor myslot :initform "")) (:documentation "class test")) (defmethod set-myslot ((obj myclass) text) (setf (myslot obj) text)) (defpackage #:tpac2 (:use #:cl) (:import-from :tpac :myslot :set-myslot) ; import what is to be exported for tpac2 (:export :myclass2 :myslot2 :myslot :set-myslot)) (in-package :tpac2) (defclass myclass2 (tpac:myclass) ((myslot2 :accessor myslot2 :initform "")) (:documentation "class test 2")) (defmethod set-myslot ((obj myclass2) text) (setf (myslot2 obj) text) (setf (myslot obj) "nope")) (defpackage #:tu (:use #:cl :tpac2) (:export start-app)) (in-package :tu) (defun start-app () (let ((obj (make-instance 'myclass2))) (set-myslot obj "test") (format t "Hello World - ~A~%" (myslot obj))))