[Prev][Next][Index][Thread]

Re: Need help with Class-Allocated Slots



Forgive me for asking the obvious, as I am sure it has been stated
before if this was discussed previously, but why isn't a direct
mechanism for accessing class slots designed into the language?

> > "Ron Franke-polz" <ron.franke-polz@iac.honeywell.com> writes:
> > 
> > > I've been playing around with slot allocation and am wondering if there is a
> > > way to access "class allocated" slots without having an instance of that
> > > class?
> > 
> > There was a discussion on this last year I think when the singleton
> > design pattern was discussed. It turns out there is no way of
> > accessing the class or each-subclass slots without an instance of the
> > class.
> > 
> > One possible work around is not to use the class allocated slot but to
> > use a normal function accessing a global variable or some similar
> > scheme.
> 
> This was probably mentioned the last time this topic came around, but one could
> use a class allocated slot, a singleton, and wrap the access to give the feel
> of direct access.
> 
> define class <foo> (<object>)
>   class slot foo-bar = #f, init-keyword: bar:;
> end class;
> 
> define constant $foo = make(<foo>);
> 
> define method foo-bar ( x == <foo> )
>   foo-bar( $foo );
> end method;
> 
> The downside is that making an instance may be costly or have resources
> associated with it that are inappropriate for such a prototype, but you could
> introduce a subclass which was specialized for this purpose.
> 
> __Jason
> 
> _____________________________________________________________________
> This message has been checked for all known viruses by Star Internet delivered
> through the MessageLabs Virus Control Centre. For further information visit
> http://www.star.net.uk/stats.asp
> 


Follow-Ups: References: