[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
glue example: Self source
- To: self-interest@myself.stanford.edu (Self mailing list)
- Subject: glue example: Self source
- From: hernan@cc.gatech.edu (Hernan Astudillo R.)
- Date: Fri, 12 Feb 93 19:05:45 EST
- Resent-date: Fri, 12 Feb 93 16:07:57 PST
- Resent-from: Urs Hoelzle <urs@otis>
- Resent-message-id: <9302130007.AA01177@otis.Stanford.Edu>
- Resent-to: real-self-interest
*** FILE greeting.self (Self counterpart of C++ code) ***
"*** Hernan Astudillo R.
 *** Dec 12, 1992
 *** greeting.self:  use foreign functions and dynamically linked-in libraries
     to interface with C++ constructors/members.
     The idea is to provide a prototype for traits the C++ class 'Greeting';
     the 'well-known' thing will be the prototype and the constructor (see
     below for reasons why I did it this way).
 ***"
traits     applications _AddSlotsIfAbsent: ( | ^ greetingClass* = () | )
prototypes applications _AddSlotsIfAbsent: ( | ^ greetingClass* = () | )
oddballs   applications _AddSlotsIfAbsent: ( | ^ greetingClass* = () | )
oddballs greetingClass _Define: ( |
    ^ comment = 'test for Self -> C++ glue'.
    "** pseudo-constructor for the 'class' Greeting **"
    ^ createGreeting: string = (
	| new. |
	'[createGreeting]' printLine.
	new: prototypes greeting copy.	"--create new instance"
	new proxyPart: (new greeting_new_glue: string).	"--initialize it"
	^new.
      ). "--end createGreeting"
    "** well-known function that returns a dead proxy (required by the form
     ** that proxy's are used. **"
    ^ greetingProto = prototypes proxy deadCopy.
| )
traits greetingClass _Define: ( |
    _ parent* = oddballs greetingClass.	"--to access related oddballs"
    "** the definition of slots (code) shared by all Greeting 'instances' **"
    ^ greeting = (|
	    _ superClassTraits * = traits proxy.
					"--to use superclass features"
	    _ applRelatedScope * = traits greetingClass.
					"--to access other greeting 'members'"
	    ^ sayIt: times = (		"--member greeting::sayIt(int)"
		'[greeting sayIt]' printLine.
		^ greeting_sayIt_glue: times.	"--glue call"
	      ).
	    ^ delete = (
		'[greeting delete]' printLine.
		^ greeting_delete_glue.		"--glue call"
	      ).
      |).
| )
"****** 4 approaches to defining the prototype (and instances) of a 'class',
	using the case of 'greeting' as subclass of 'proxy'.  No new data is
	needed, but just to add some behavior."
"** (1) keep the super-class(es) prototype(s) as components, using refs. and
	proper initialization; the components must be parents too (*), so
	any message not understood by the obj. is forwarded to its component;
	this requires that the traits-parent be (**), to override any
	component behavior.
	In general, it is not enough to delegate to the super-class traits,
	because some behaviors of the component obj. (not of the component
	traits) may be wanted too.
	-- Notice that certain messages (like primitives) do not follow the
	delegators, but look at the slots in the object itself.
	-- Notice that this leaves a proper object initialization in hands of
	an external agent, or of any object that copies this prototype
	directly."
"*** NOT IN USE ***
prototypes greetingClass _Define: ( |
    ^ greeting = (|
	    _ classTraits ** = traits greeting.
	    _ thisObjectPrints = true.
	    ^ proxyPart *.
      |).
| )
 *** END (1) ***"
"** (2) if not every behavior/slot of the super-class component is desired,
	then the component doesn't need to be a parent (or if some
	delegation- oblivious primitive is present, it cannot be a component).
	Any wanted behavior should be implemented explicitly.
	-- Like in (1), initialization is left to an external agent or to
	copying clients."
"*** CODE IN USE ***"
prototypes greetingClass _Define: ( |
    ^ greeting = (|
	    _ classTraits * = traits greeting.
	    _ thisObjectPrints = true.
	    ^ proxyPart.
	    ^ printString = ( proxyPart printString. ).
	    ^ reviveIfFail: t0 = ( proxyPart reviveIfFail: t0. ).
      |).
| )
"*** END (2) ***"
"** (3) copy the super-class prototype by hand, and add whatever is needed
	(in this example, only a parent slot for the sub-class traits).
	Notice that any changes to the super-class prototype must be
	reflected BY HAND on the sub-class prototype!!"
"** (4) to maintain integrity, instead of (3), we can copy (at loading time)
	the super-class prototype, and the add/replace whatever is needed.
	This ensures consistency."
"*** NOT IN USE ***
prototypes greetingClass _Define: ( |
    ^ greeting.
| )
prototypes greetingClass greeting: proxy deadCopy
prototypes greeting _AddSlotsIfAbsent: ( |
    ^greetingTraits ** = traits greeting.
| )
 *** END (4) ***"
'greetingGlue.wrappers' _RunScript