home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
pub
/
scripts
/
ckermit
/
oop
< prev
next >
Wrap
Text File
|
2020-01-01
|
2KB
|
82 lines
; From: Dat Thuc Nguyen
; Newsgroups: comp.protocols.kermit.misc
; Subject: Object-Oriented Programming in Kermit 95
; Date: Tue, 23 Mar 1999 14:45:09 GMT
; URL: http://www.smalltickle.com
;
; OBJECT-ORIENTED PROGRAMMING IS VERY EFFECTIVE IN DESIGNING
; AND MAINTAINING SOFTWARE.
; KERMIT 95 PROVIDES MECHANISMS TO IMPLEMENT ELEGANTLY SOME
; OBJECT-ORIENTED FEATURES.
; THE FOLLOWING SCRIPT DEFINES A CLASS PERSON WITH TWO DATA
; ATTRIBUTES age, job AND TWO METHODS introduce, destroy.
; ALL DATA ATTRIBUTES AND METHODS ARE PUBLIC.
define PERSON {
_assign \%1.age \%2
_assign \%1.job \%3
_assign \%1.introduce {
echo My name is \%1
echo I am \\m(\%1.age) years old
echo I am a \\m(\%1.job)
}
_assign \%1.destroy {
_define \%1.age
_define \%1.job
_define \%1.introduce
}
}
; RECENTLY I MET MARK, A 36 YEARS OLD TRUCK DRIVER
person mark 36 {truck driver}
; HE INTRODUCES HIMSELF
mark.introduce
; HE IS WITH HIS GIRL FRIEND, JANE, A 28 YEARS YOUNG SECRETARY
person jane 28 secretary
; SHE ALSO INTRODUCES HERSELF
jane.introduce
; THEY ARE OFF ON VACATION, I ERASE THEM FROM MY MEMORY
mark.destroy
jane.destroy
; FOLLOWING IS THE CLASS ANIMAL
define ANIMAL {
_assign \%1.sound \%2
_assign \%1.introduce {
echo I am a \%1 ... \\m(\%1.sound)
}
_assign \%1.destroy {
_define \%1.sound
_define \%1.introduce
}
}
; IN FRONT OF NY HOUSE, THERE IS A DOG
animal dog woof
; AND A CAT
animal cat miaou
; THE DOG TRIES TO BE FRIENDLY
dog.introduce
; THE CAT REPLIES
cat.introduce
; I CLOSE THE WINDOW AND FORGET ABOUT THEM
dog.destroy
cat.destroy
; Different objects react differently to the same message, it's polymorphism!
; If you want to modify the behavior of all the objects in the same class,
; do it in the class definition, no need to browse through the code to update
; them. That's efficiency.
end