Classes as slots in other classes and package definition
Posted: Tue Nov 02, 2010 2:35 pm
Hello,
I wrote three classes (each in a single file) and wanted to use two of the classes as slots in the first class.
Two of the slots in the unit class are the unit-type and the unit-attributes class.
The unit class:
The unit-type and the unit-attributes classes:
My questions:
(1)
If I initialize the unit class with make-instance, do I also have to initialize the slot values of the unit-type and the unit-attributes classes with make-instance?
(2)
These classes are in an adt directory. I read about the packages macro (defpackage) and the in-package method. Where do I have to put the defpackage definition and where do I have to use in-package? I did not really understand the way, where to put the methods and where to load the classes.
Many thanks for any answers.
I wrote three classes (each in a single file) and wanted to use two of the classes as slots in the first class.
Two of the slots in the unit class are the unit-type and the unit-attributes class.
The unit class:
Code: Select all
(defclass unit()
((unit-name
:initarg :unit-name
:initform (error "Must supply an unit name.")
:accessor unit-name
:documentation "Name of the unit.")
(unit-race
:initarg :unit-race
:initform (error "Must supply an unit race.")
:accessor unit-race
:documentation "Race of the unit.")
(unit-type
:initarg :unit-type
:initform (error "Must supply an unit type.")
:accessor unit-type
:documentation "Type of the unit.")
(unit-attributes
:initarg :unit-attributes
:initform (error "Must supply unit attributes.")
:accessor unit-attributes
:documentation "The attributes of the unit.")
(unit-size)
(unit-equipment)
(unit-rules)
(unit-options))
(:documentation "A figure or a group of figures that represent one unit."))
Code: Select all
(defclass unit-type()
((name
:initarg :name
:initform (error "Must supply a type name.")
:accessor name
:documentation "Name of the unit."))
(:documentation "Type of the unit like hero, specialist or squad."))
(defclass unit-attributes()
((strength
:initarg :strength
:initform (error "Must supply a strength.")
:accessor strenth
:documentation "Strength of the unit.")
(dexterity
:initarg :dexterity
:initform (error "Must supply a dexterity.")
:accessor dexterity
:documentation "Dexterity of the unit."))
(:documentation "Attributes of the unit like strength, dexterity, etc."))
(1)
If I initialize the unit class with make-instance, do I also have to initialize the slot values of the unit-type and the unit-attributes classes with make-instance?
(2)
These classes are in an adt directory. I read about the packages macro (defpackage) and the in-package method. Where do I have to put the defpackage definition and where do I have to use in-package? I did not really understand the way, where to put the methods and where to load the classes.
Many thanks for any answers.