View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] Suggestion needed

From: Stefan Sobernig <stefan.sobernig_at_wu.ac.at>
Date: Tue, 20 Jan 2015 10:11:35 +0100

A more complete solution (preserving any pre-existing superclass lists)
is as follows:

package req nx

namespace eval ::vitick {

   Class create Object -superclasses nx::Object

   Class create Class -superclasses nx::Class {
     :method init {} {
       ##
       ## Rewire the default superclass
       ##
       if {[:info superclasses] eq "::nx::Object"} {
        :configure -superclasses [namespace current]::Object
       }

     }
   }

   namespace export Object Class
}

namespace import -force ::vitick::*

puts [[Class create MyClass] info superclasses]; # default is:
::vitick::Object
puts [[Class create AnotherClass -superclasses MyClass] info
superclasses]; # ::MyClass
puts [[Class create AnotherClass -superclasses MyClass] info
superclasses -closure]; # ::MyClass ::vitick::Object ::nx::Object

//stefan

> Hi Victor,
>
> > Any suggestions?
>
> As always, there are several options. One way of nursing our custom
> Object/Class is to use proper specializations of nx::Object/nx::Class:
>
> package req nx
>
> namespace eval ::vitick {
>
> Class create Object -superclass nx::Object
>
> Class create Class -superclass nx::Class {
> :method init {} {
> :configure -superclasses [namespace current]::Object
> }
> }
>
> namespace export Object Class
> }
>
> namespace import -force ::vitick::*
>
> This is less invasive and you have the benefit of monitoring any
> changes/additions to nx::Object/nx::Class for free.
>
> Cheers,
> Stefan
> _______________________________________________
> Xotcl mailing list
> Xotcl_at_alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl


-- 
Institute for Information Systems and New Media
Vienna University of Economics and Business
Welthandelsplatz 1, Building D2, A-1020 Vienna
Austria
http://nm.wu.ac.at/en/sobernig
stefan.sobernig_at_wu.ac.at
ss_at_thinkersfoot.net
t. +43-1-31336-4878
f. +43-1-31336-746