Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

design question

5 views
Skip to first unread message

Erik Naggum

unread,
Apr 16, 2001, 12:41:49 PM4/16/01
to
* isc...@hotmail.com
> What's the best design for such a system where an object inherits not from
> another class, but from an _instance_ of a class?

I would use a slot named "inherits-from" and write a slot-unbound method
that looks up the value of any unbound slots in this object in the object
pointed to by that slot, instead. This affords a dynamic inheritance
mechanism.

If the inheritance is static, i.e., the value of any unspecified slots is
_copied_ into the object that inherits from the parent object, do the
copy before you do any other initialization.

#:Erik
--
I found no peace in solitude.
I found no chaos in catastrophe.
-- :wumpscut:

martti....@solibri.com

unread,
Apr 16, 2001, 3:26:26 PM4/16/01
to
isc...@hotmail.com writes:

> I need to design a system that handles stylesheets for rtf files. Just like in
> CSS (cascading style sheets) for html, a style may inherit properties from
> another style. For example:
>
> Style A: Font Arial, Size 12
> Style B: Bold, inherits everythng else from Style A, resulting in Arial, 12,
> bold


>
> What's the best design for such a system where an object inherits not from
> another class, but from an _instance_ of a class?


One system doing something like this would be the KR
knowledge-representation part in the Garnet GUI system.
- Non-CLOS stuff, though.

--

Tim Bradshaw

unread,
Apr 16, 2001, 3:46:36 PM4/16/01
to
* iscaris wrote:
> Style A: Font Arial, Size 12
> Style B: Bold, inherits everythng else from Style A, resulting in Arial, 12,
> bold

> What's the best design for such a system where an object inherits not from
> another class, but from an _instance_ of a class?

This is what I use. It's not necessarily the best solution or the
best implementation of that solution.

(defclass defaulting-mixin ()
((defaulting-parent :initform nil
:initarg :defaulting-parent)))

(defgeneric slot-value/defaulting (o slot-name))

(defmethod slot-value/defaulting (o slot-name)
(slot-value o slot-name))

(defmethod slot-value/defaulting ((o defaulting-mixin) slot-name)
(if (and (slot-exists-p o slot-name)
(slot-boundp o slot-name))
(slot-value o slot-name)
;; might not want to blunder on regardless here.
(slot-value/defaulting (slot-value o 'defaulting-parent)
slot-name)))

--tim

Vladimir V. Zolotych

unread,
Apr 17, 2001, 5:07:24 AM4/17/01
to
Tim Bradshaw wrote:
>
> (defgeneric slot-value/defaulting (o slot-name))

What purpose this above serves for ? Would you mind say
few words about that ?

--
Vladimir Zolotych gsm...@eurocom.od.ua

Vladimir V. Zolotych

unread,
Apr 17, 2001, 5:45:07 AM4/17/01
to
Erik Naggum wrote:
>
> If the inheritance is static, i.e., the value of any unspecified slots is
> _copied_ into the object that inherits from the parent object, do the
> copy before you do any other initialization.

I'm new to CLOS. Would you mind to explain what do you mean in the
sayings above, especially in "...do the copy before you do any other
initialization."

--
Vladimir Zolotych gsm...@eurocom.od.ua

Tim Bradshaw

unread,
Apr 17, 2001, 7:07:53 AM4/17/01
to
"Vladimir V. Zolotych" <gsm...@eurocom.od.ua> writes:

> Tim Bradshaw wrote:
> >
> > (defgeneric slot-value/defaulting (o slot-name))
>
> What purpose this above serves for ? Would you mind say
> few words about that ?

It doesn't really do anything in this case other than to serve as an
indication that I'm going to define some methods on this GF. I tend
to use DEFGENERIC even when it's not needed because it gives some
central place to put documentation or commentary (in this case there's
neither, sorry!).

I actually improved this stuff somewhat last night, I'll post the
souped-up one tonight (UK time) when I have access to my home machines
again. It makes SLOT-VALUE/DEFAULTING return a second value which is
the object where the slot was found which tells you if it was a
default or directly present in the original instance, and has some
macrology to define defaulting accessors.

--tim

Marco Antoniotti

unread,
Apr 17, 2001, 10:01:12 AM4/17/01
to

Tim Bradshaw <t...@tfeb.org> writes:

> "Vladimir V. Zolotych" <gsm...@eurocom.od.ua> writes:
>
> > Tim Bradshaw wrote:
> > >
> > > (defgeneric slot-value/defaulting (o slot-name))
> >
> > What purpose this above serves for ? Would you mind say
> > few words about that ?
>
> It doesn't really do anything in this case other than to serve as an
> indication that I'm going to define some methods on this GF. I tend
> to use DEFGENERIC even when it's not needed because it gives some
> central place to put documentation or commentary (in this case there's
> neither, sorry!).

THere is another good use of DEFGENERIC. Suppose you are writing a
large system and that you have a "protocol" that must be obeyed by
subclasses (some of which do depend on other parts of the system).
E.g.

File 1:

(defclass a-root () ())

(defgeneric f (a-root))
(defgeneric g (a-root))

File 2:

(defun foo (x)
(f x))

File 3:

(defclass another-root () ())

File 4:

(defclass the-real-mccoy (a-root another-root) ())

(defmethod f ((x the-real-mccoy)) ...)


In this case you can make File 2 depend only on File 1. 'f' will be
recognized as a generic function and you will avoid warnings (or
errors) depending on your PCL implementation.
On top of that you do achieve modularization.

Cheers

--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
719 Broadway 12th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.

Jochen Schmidt

unread,
Apr 17, 2001, 12:23:49 PM4/17/01
to
Vladimir V. Zolotych wrote:

> Erik Naggum wrote:
>>
>> If the inheritance is static, i.e., the value of any unspecified slots
>> is _copied_ into the object that inherits from the parent object, do
>> the copy before you do any other initialization.
>
> I'm new to CLOS. Would you mind to explain what do you mean in the
> sayings above, especially in "...do the copy before you do any other
> initialization."

If you copy the "static-inherited" values before any other initialization,
then it is possible to overwrite them by using initialization-keyword args
in make-instance or when using a :initform in a subclass.

Regards,
Jochen

0 new messages