Posted to tcl by hypnotoad at Mon Jun 01 16:35:09 GMT 2015view raw

  1. package require oo::meta
  2.  
  3. oo::class create small_class {
  4. constructor {} {}
  5. method hello {} {puts hello}
  6. }
  7.  
  8. oo::class create large_class {
  9. property deputy first {class small_class}
  10. property deputy second {class small_class}
  11.  
  12. constructor {} {
  13. foreach {name desc} [my meta get deputy] {
  14. set class [dict get $desc class]
  15. set obj [$class create $name]
  16. my meta set child $name $obj
  17. $obj meta set $obj parent [self]
  18. }
  19. }
  20.  
  21. method hello {} {
  22. foreach {name obj} [my meta get child] {
  23. $obj hello
  24. }
  25. }
  26. }
  27.  
  28. large_class create myLargeObject
  29. myLargeObject hello
  30. myLargeObject first hello
  31. myLargeObject second hello