; From: Dat Thuc Nguyen ; Newsgroups: comp.protocols.kermit.misc ; Subject: Inheritance in Kermit 95 ; Date: Mon, 29 Mar 1999 15:57:20 GMT ; URL: http://www.smalltickle.com ; ; NO OBJECT-ORIENTED PROGRAMMING LEAVES HOME WITHOUT INHERITANCE. ; THE FOLLOWING SCRIPT DISPLAYS INHERITANCE IN KERMIT 95. ; ; CLASS PERSON IS THE BASE CLASS. ; ; CLASS EMPLOYEE DERIVES FROM CLASS PERSON. CLASS EMPLOYEE HAS ; ALL ATTRIBUTES AND BEHAVIOR OF CLASS PERSON AND SOME EXTRAS ; ; CLASS MANAGER DERIVES FROM CLASS EMPLOYEE. CLASS MANAGER HAS ; ALL ATTRIBUTES AND BEHAVIOR OF CLASS EMPLOYEE AND SOME EXTRAS ; ; THE KEY OF OBJECT-ORIENTED PROGRAMMING IN KERMIT 95 IS ; THE PROPER USAGE OF: ; ; ASSIGN : ASSIGN EXPANDS ONLY R-VALUE VARIABLE. ; _ASSIGN : _ASSIGN EXPANDS BOTH L-VALUE AND R-VALUE VARIABLES. ; DEFINE : DEFINE EXPANDS NEITHER L-VALUE NOR _R-VALUE VARIABLES. ; _DEFINE : _DEFINE EXPANDS ONLY L-VALUE VARIABLE. ; define PERSON { local self assign self \%1 _assign \m(self).age \%2 _assign \m(self).job \%3 _assign \m(self).introduce { echo My name is \fcap(\%1) echo I am \\m(\m(self).age) years old echo I am a(n) \\m(\m(self).job) } _assign \m(self).destroy { _define \m(self).age _define \m(self).job _define \m(self).introduce _define \m(self).destroy } } define EMPLOYEE { local self super \%s assign self \%1 assign super person ; DERIVES FROM PERSON \m(super) {\%1} {\%2} {\%3} ; CREATE BASE COMPONENTS assign \%s \m(self).introduce ; SAVE SUPER CLASS METHOD ; introduce _assign \m(self).introduce { ; OVERLOAD METHOD introduce \m(\%s) ; EXEC SUPER CLASS METHOD FIRST echo I work for \%4 ; AND THIS EXTRA } } define MANAGER { local self super \%s assign self \%1 assign super employee ; DERIVES FROM EMPLOYEE \m(super) {\%1} {\%2} {\%3} {\%4} ; CREATE BASE COMPONENTS assign \%s \m(self).introduce ; SAVE SUPER CLASS METHOD _assign \m(self).introduce { ; OVERLOAD METHOD introduce \m(\%s) ; EXEC SUPER CLASS METHOD FIRST echo I am a manager ; AND THIS EXTRA } _define \m(self).fire { ; ADD THE NEW METHOD fire echo {\%1, you are fired} } _define \m(self).offer { ; ADD THE NEW METHOD hire echo {\%1, I would like to offer you \%2} } } ; JANE IS A 27 YEARS YOUNG STUDENT person Jane 27 student Jane.introduce echo ; MARK IS A 36 YEARS OLD PROGRAMMER WORKING FOR BT&T employee Mark 36 programmer BT&T Mark.introduce echo ; MARIO IS A 24 YEARS OLD PROGRAMMERS WORKING FOR METAS employee Mario 24 programmer METAS Mario.introduce echo ; BOB IS A 47 YEARS OLD ENGINEER WORKING FOR METAS AS A MANAGER manager Bob 47 Engineer METAS Bob.introduce echo ; MARIO KNOWS NO DIFFERENCE BETWEEN DEFINE AND _DEFINE. ; Bob DECIDES TO FIRE HIM: Bob.fire Mario echo ; MARK KNOWS THE DIFFERENCE BETWEEN ASSIGN AND _ASSIGN. ; Bob DECIDES TO MAKE HIM AN OFFER: Bob.offer Mark 100K echo end