On Tue, 2003-01-21 at 13:53, Art Eschenlauer wrote:
> My solution was to create a Type() method that generates the class' name 
> followed by the names of the superclasses. FFI, please see
> http://eudyptula.freezope.org/uunit/uunit.icn.html
> from which this snippet is snipped:
> 
>   method Type(
>     # Produces the name of the class and its superclasses
>    )
>     # Since there is little (if any) reason not to subclass TestCase, 
>     #   generate its name after generating name of subclass.
>     every suspend ( type(self) ? tab(upto('_')\1) ) | "TestCase" | "Test"
>   end

Thanks.  I've done something similar using a base class:
----------------------------------------------------
class TypedClass(chain)

    method instanceof(superClassName)
        myClassName := getClassname(self)
        chain ? {
            if tab(find(myClass)) & find(superClassName) then
                return superclass
            }
    end

    method addSubclass(subclass)
        chain := subclass || " " || chain
        return chain
    end

    method getClassname(aClass)
        return (type(aClass) ? tab(find("__")))
    end
        
    initially
        /chain := "TypedClass "
end
----------------------------------------------
Which other classes can then inherit.  (I think the philosophy is
the same as what you've done, but this way the writer of a class
doesn't need to know the full inheritance chain, just its parent
class(es).)  For example:
----------------------------------------------
class A : TypedClass ()

    initially
        self.TypedClass.initially()
        self.TypedClass.addSubclass("A")
end

class B: A ()

    initially
        self.A.initially()
        self.TypedClass.addSubclass("B")
end

procedure main()
    b := B()
    write()
    if b.instanceof("A") then
        write("B is an instance of A")
    else
        write("B is NOT an instance of A")
end
-------------------------------------------------------------

However, I'm not completely happy with it, for a variety of reasons:

(1) Relies on there being no user-created classes with "__" in the
    name.
(2) Relies on user remember to subclass TypedClass (thank heaven
    for multiple inheritance, at least!)
(3) Won't work correctly with multiple inheritance!
(4) Relies on user remembering correct sequence of steps to do
    in initially clause.
(5) No easy way for 'instanceof' method to return the superclass.

-- 
Steve Wampler <[EMAIL PROTECTED]>
National Solar Observatory


-------------------------------------------------------
This SF.net email is sponsored by: Scholarships for Techies!
Can't afford IT training? All 2003 ictp students receive scholarships.
Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
www.ictp.com/training/sourceforge.asp
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to