-
class Person {
-
public variable name ""
-
public variable phone ""
-
public variable email ""
-
-
constructor {args} {
-
eval configure $args
-
}
-
}
This class has three public attributes: the person's name, phone number
and e-mail address. Any extra args passed to the constructor are treated
as configuration options and passed along to configure. A Person object
can be created like this:
-
Person bob -name "Cyber Bob"
-
-phone "555-4bob"
-
-email "cbob@foo.com"
-
-
and reconfigured like this:
-
-
bob configure
-
=> {-email {} cbob@foo.com} {-name {} {Cyber Bob}} {-phone {} 555-4bob}
-
-
bob configure -phone
-
=> -phone {} 555-4bob
-
-
bob configure -phone 1-800-num-4bob
-
=>
-
-
bob cget -phone
-
=> 1-800-num-4bob
阅读(165) | 评论(0) | 转发(0) |