Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add some titles to the examples |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
8b7522e1b5f7f83e9b58d973113f9a56 |
User & Date: | dkf 2018-05-27 10:35:37.367 |
Context
2018-05-27
| ||
10:43 | A few more notes on exporting, and lengthen some very short paragraphs by combining them. check-in: a023e48805 user: dkf tags: trunk | |
10:35 | Add some titles to the examples check-in: 8b7522e1b5 user: dkf tags: trunk | |
2018-05-26
| ||
09:49 | Fixed typo in JO's name (SHAME!) check-in: 22823b2821 user: fbonnet tags: trunk | |
Changes
Changes to tip/500.md.
︙ | ︙ | |||
308 309 310 311 312 313 314 315 316 317 318 319 320 321 | A supporting introspector is also added, **info object creationid**, which returns the creation ID of any existing object. It also applies to classes. Again, note that creation IDs are _always_ system-allocated and are _never_ guaranteed to be unique between interpreters, either in multiple processes or in the same thread or process; they are only ever locally unique. # Examples This example shows a private variable linked to a Tk entry: oo::class create Editable { variable w; # Allow subclasses to see this private variable val; # Hide this from subclasses | > > | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | A supporting introspector is also added, **info object creationid**, which returns the creation ID of any existing object. It also applies to classes. Again, note that creation IDs are _always_ system-allocated and are _never_ guaranteed to be unique between interpreters, either in multiple processes or in the same thread or process; they are only ever locally unique. # Examples ## Example: Private Variables and Tk This example shows a private variable linked to a Tk entry: oo::class create Editable { variable w; # Allow subclasses to see this private variable val; # Hide this from subclasses |
︙ | ︙ | |||
340 341 342 343 344 345 346 347 348 349 350 351 352 353 | } Editable create field .e field trace {args { puts "field is now [field value]" }} field value "Set the contents" Ths is an example of private methods. It shows how private methods can be used to manage the complexity of a method without making its API (as exposed to either subclasses or the rest of Tcl) overly complex. oo::class create Modulator { # The exported interface to the class | > > | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | } Editable create field .e field trace {args { puts "field is now [field value]" }} field value "Set the contents" ## Example: Private Methods and Code Complexity Management Ths is an example of private methods. It shows how private methods can be used to manage the complexity of a method without making its API (as exposed to either subclasses or the rest of Tcl) overly complex. oo::class create Modulator { # The exported interface to the class |
︙ | ︙ | |||
390 391 392 393 394 395 396 397 398 399 400 401 402 403 | # invoked from within # "::oo::Obj15 modulate 5 6 7 8" catch {$m no.such.method} msg puts $msg # Prints something like: # unknown method "no.such.method": must be destroy or modulate This is a combined example of private methods and variables. oo::class create LabelEqual { constructor {label} { set [my varname label] $label } | > > | 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | # invoked from within # "::oo::Obj15 modulate 5 6 7 8" catch {$m no.such.method} msg puts $msg # Prints something like: # unknown method "no.such.method": must be destroy or modulate ## Example: Private Methods and Variables Working Together This is a combined example of private methods and variables. oo::class create LabelEqual { constructor {label} { set [my varname label] $label } |
︙ | ︙ | |||
445 446 447 448 449 450 451 452 453 454 455 456 457 458 | puts "one=[$expr1 value] two=[$expr2 value]" # Prints: # one=6 two=6 puts [info vars [info object namespace $expr1]::*] # Prints something like: # {::oo::Obj13::11 : label} ::oo::Obj13::label This example highlights the behaviour of private variables and `info object creationid`: # A simple introspection procedure for classes proc dumpinfo cls { puts "class ID of $cls is [info object creationid $cls]" | > > | 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | puts "one=[$expr1 value] two=[$expr2 value]" # Prints: # one=6 two=6 puts [info vars [info object namespace $expr1]::*] # Prints something like: # {::oo::Obj13::11 : label} ::oo::Obj13::label ## Example: Private Variable Naming and Creation IDs This example highlights the behaviour of private variables and `info object creationid`: # A simple introspection procedure for classes proc dumpinfo cls { puts "class ID of $cls is [info object creationid $cls]" |
︙ | ︙ |