Re: Referencing values in an array
- From: stefan <stefan.sobernig@xxxxxxxxxxxxx>
- Date: Tue, 29 Jul 2008 02:48:18 -0700 (PDT)
Daniel,
thanks a lot for your message and help.
I'm still a bit confused as I'm totally new to TCL and I'm not sure if I
understand all your suggestions and how they would make my (actually
more complex) application easier or more elegant.
I do not know either whether they turn your entire application easier
or more
elegant, but at least the code snippet you posted ...
btw: What is the difference between "my" and "self"? Does "my" reference
the instance and self the current object/methode "self" is in?
"my" is perfectly equivalent to [self] (see below for a changed
snippet)
2. You seem to devise the shapes array as devise to store MyShape
instances in
an addressable "store". Well, you double your efforts here, that's
what an object system
should do for you. XOTcl does (in many flavours).
Well, I have many Slides each with a lot of shapes (it's a powerpoint
import application). So I don't want to have ALL instances of MyShape
but only instances of a given slide. This might be doable by defining
another identifier for the slide but creating a container holding the
references to all instances is the typical way I used to program. There
might be better solutions especially in tcl.
Whatever is your design setting! The issue is simply whether you still
want
to devise arrays as reference container for XOTcl objects and pass
arrays
around by means of upvar/uplevel ... it does not really foster a
design based on
locality, as proposed by object orientation.
Including slides and per-slide aggregations of shapes is just a little
step further:
Class Slide -slots {
Attribute shapes -multivalued true
}
Slide proc import {numberOfShapes} {
#
# provide a new slide instance
# "my" is equivalent to [self]:
# reads: "set slide [::Slide new]"
#
set slide [my new]
#
#
# Import shapes
#
for {set i 0} {$i < $numberOfShapes} {incr i} {
# "new" assigns an auto-generated
# identifier to the created object.
set shape [::MyShape new -position $i]
$slide shapes add $shape
}
return $slide
}
Class MyShape -slots {
Attribute position
}
#
# driving range
#
set newlyImportedSlide [Slide import 5]
foreach shape [$newlyImportedSlide shapes] {
puts "*** shape: [$shape position]"
}
It just leverages the luxury of object identites, so
you can use object identities to represent logical identities in your
design (a particular slide, a particular shape, ...).
//stefan
.
- Follow-Ups:
- Re: Referencing values in an array
- From: Daniel Kirsch
- Re: Referencing values in an array
- References:
- [XOTcl] Referencing values in an array
- From: Daniel Kirsch
- Re: [XOTcl] Referencing values in an array
- From: Daniel Kirsch
- Re: Referencing values in an array
- From: stefan
- Re: Referencing values in an array
- From: Daniel Kirsch
- [XOTcl] Referencing values in an array
- Prev by Date: Re: Referencing values in an array
- Next by Date: Re: New Canvas
- Previous by thread: Re: Referencing values in an array
- Next by thread: Re: Referencing values in an array
- Index(es):
Relevant Pages
|