Classes and subclass question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Classes and subclass question

Jeff M.
Hmm. It was difficult to come up with a good subject heading for the 2
questions I have. Basically, I'd like to have a function that does 2
things:

1. Given a class name, create an instance of that class and
2. Assert that it is a subclass of a known class.

I could live without (1), but would like (2) regardless. Basically, I
have a class derived from ShellView, that overrides certain
functionality I'd like maintained (eg, events and some other methods
that I would like have "guaranteed" to be there).

Given how reflective Smalltalk is, both of these seem trivial, but I
haven't found a way to do it quite yet. Any tips?

Thanks!

Jeff M.


Reply | Threaded
Open this post in threaded view
|

Re: Classes and subclass question

Jeff M.
Okay, hehe. Nevermind about question (1). I tried the obvious and it
worked.

Jeff M.


Reply | Threaded
Open this post in threaded view
|

Re: Classes and subclass question

Ian B
In reply to this post by Jeff M.
Jeff,

>1. Given a class name, create an instance of that class and

x := (Smalltalk at: 'Ball') new.

>2. Assert that it is a subclass of a known class.

 (using a class name)
x  class allSuperclasses includes: (Smalltalk at: 'Object')

or (using a class)

x  class allSuperclasses includes: Object
--
Ian

The From address is valid - for the moment


Reply | Threaded
Open this post in threaded view
|

Re: Classes and subclass question

Bill Dargel
Ian B wrote:
> Jeff,
>>2. Assert that it is a subclass of a known class.
> x  class allSuperclasses includes: Object

Or just slightly more direct:
    aClass inheritsFrom: topClass
;-)

--
Bill Dargel            [hidden email]
Shoshana Technologies
100 West Joy Road, Ann Arbor, MI 48105  USA