On Monday, December 2, 2019 at 3:16:59 PM UTC-8, jeosol wrote:
As an over-arching comment, I think that finding yourself in a situation where
you are creating classes that represent the cross-product of a set of other
classes is not really what you want to be doing.
One of the points of using CLOS instances is to be able to treat the instances
as interchangeable. You may, in fact, be doing this if you have a certain set
of methods that are differentiated by class, but it seems rather counter to a
lot of class design to require the user to know about all of these combinatoric
subclasses in order to create the instances.
One should also remember that subclassing is not the only way to organize a
set of objects of different types. Sometimes doing an aggregation of different
types and using delegation can make more sense.
You may also need to provide a more concrete example of what you want to get
from these classes and their instances, as the abstract description doesn't
really give me a good idea of what final behavior you are trying to achieve.
Post by jeosol
Good morning all,
I have a CLOS design question and wanted to see if there is a better way of doing what I'm trying to do and doing already. I'll keep it brief.
Basically, I have 3 concepts (A,B,C) and each can take different possibilities (or sub concepts). For each subconcept, some slots take a particular value (e.g., simply setting the to T or nil or some value). For example imagine B is a concept on status (ON/OFF) with subconcepts B1 (ON) and B2 (OFF).
What behavior do you want if you change the slot value on one of these
instances? Do you want it to change class? Or are the slot values immutable?
Post by jeosol
For the testing, I'll need to get the options/or settings for all 3 concepts, A-B-C, that then fully specifies the case.
defclass base-class ()
((... add all the slots ...))
(defclass A-B-C (base-class) () ...)
(defclass A1-B-C (A-B-C) () ...)
you probably get my point. I am creating specific cases for the combination (handful) but it's getting messy.
I use :default-initargs appropriately to initialize slots as needed.
Alternative approach (not tested or scoped out).
(defclass A1-B-C (A B C) () ...) and the slots are combined from the base classes of A, B, C. (Note A, B, C are different and are only useful when combined).
If the classes are only useful when combined, why do you separate them out?
Perhaps a simpler solution than trying to do all combinations is to create a
single class that has slots for A, B and C.
Also, do you want instances of A1-B-C to be able to play the role of just an A
or just a B, etc? Remember that subclasses should semantically be sub-types. If
it is some other form of relationship, you should use a different mechanism.
You could then have process the class based on various attributes of the
classes. Or define predicates for combinations that make some semantic sense
and use those for guiding your processing?
I suppose that the fundamental question is what benefit to you seek from
generating all of these combination classes?
Post by jeosol
For my testing, I need to be able to create an instance of a class for a specific case: e.g., A1-B2-C3
For that I have a generic create-object-method with (type :name), for example,
(defmethod create-object ((obj-type (eql :A1-B2-C3)) ..) to create the cases (not for all class combinations) but as much as needed to be able allow adequate differentiation (e.g., A1-B2-C3 may be have same slots and settings for A1-B2-C2) but is treated differently based on class name.
This seems to be a bit of a reinvention of MAKE-INSTANCE. It would seem that
you would not need to introduce this new function, but just be able to create
instances and have the appropriate initialization methods run for your classes.
Post by jeosol
My approach follows the file streams example in Sonja Keene's text book.
What do you guys think? Comments?
Perhaps what you want to use is something like a more fluid concept-based
knowledge representation system such as the old Loom(R) and more recent
PowerLoom(R) systems from the University of Southern California's Information
Sciences Institute. These are open-source knowledge representation systems
available in Common Lisp.
They allow you to define concepts (similar to classes) where the membership can
be determined by the value of relations (similar to slots) dynamically. Loom
supports methods, although PowerLoom does not.