Posted to tcl by aspect at Fri Nov 24 14:19:47 GMT 2017view raw
- oo::class create Person {
- variable age
- variable sex
- constructor {Name Age Sex} {
- set name $Name
- set age $Age
- set sex $Sex
- my Invariants
- }
- method Invariants {} {
- puts "Testing invariants: $age $sex"
- if {$age >= 0 && $age < 120} {} {error "Age must be between 0 and 120."}
- if {$sex == "M" || $sex == "F"} {} {error "Sex must be M or F"}
- }
- method InvariantsFilter args {
- next {*}$args
- my Invariants
- }
- filter InvariantsFilter
- method set_age {years} {
- set age $years
- }
- method change_sex {mf} {
- set sex $mf
- }
- }
- Person create jim "Jim Bob" 5 M
- jim set_age 300