54
|
1 |
'From Smalltalk/X, Version:2.10.5 on 26-mar-1995 at 12:13:28 pm'!
|
|
2 |
|
|
3 |
Object subclass:#Plug
|
|
4 |
instanceVariableNames:'simulatedProtocol'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Kernel-Objects'
|
|
8 |
!
|
|
9 |
|
|
10 |
!Plug class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
version
|
|
13 |
"
|
|
14 |
$Header: /cvs/stx/stx/libview2/Plug.st,v 1.1 1995-03-26 15:05:23 claus Exp $
|
|
15 |
"
|
|
16 |
!
|
|
17 |
|
|
18 |
documentation
|
|
19 |
"
|
|
20 |
A Plug is an objcet which simulates a protocol and evaluates
|
|
21 |
a corresponding block when receiving messages.
|
|
22 |
Its main use is for the demo doIts, to play the role of a model.
|
|
23 |
Plugs are not used in the system and exist as a demo only.
|
|
24 |
This class may be changed/removed/replaced without notice.
|
|
25 |
"
|
|
26 |
!
|
|
27 |
|
|
28 |
examples
|
|
29 |
"
|
|
30 |
|plug|
|
|
31 |
|
|
32 |
plug := Plug new.
|
|
33 |
plug respondTo:#foo with:[Transcript showCr:'received foo'].
|
|
34 |
plug respondTo:#foo: with:[:arg | Transcript showCr:'received foo: ', arg printString].
|
|
35 |
|
|
36 |
plug foo.
|
|
37 |
plug foo:'some argument'
|
|
38 |
"
|
|
39 |
! !
|
|
40 |
|
|
41 |
!Plug class methodsFor:'initialization'!
|
|
42 |
|
|
43 |
initialize
|
|
44 |
superclass := nil
|
|
45 |
! !
|
|
46 |
|
|
47 |
!Plug class methodsFor:'instance creation'!
|
|
48 |
|
|
49 |
new
|
|
50 |
^ super basicNew privateInitialize
|
|
51 |
! !
|
|
52 |
|
|
53 |
!Plug methodsFor:'protocol definition'!
|
|
54 |
|
|
55 |
respondTo:aSelector with:aBlock
|
|
56 |
simulatedProtocol at:aSelector put:aBlock
|
|
57 |
! !
|
|
58 |
|
|
59 |
!Plug methodsFor:'message sending'!
|
|
60 |
|
|
61 |
doesNotUnderstand:aMessage
|
|
62 |
|block|
|
|
63 |
|
|
64 |
block := simulatedProtocol at:aMessage selector ifAbsent:[].
|
|
65 |
block isNil ifTrue:[
|
|
66 |
^ super doesNotUnderstand:aMessage
|
|
67 |
].
|
|
68 |
^ block valueWithArguments:(aMessage arguments)
|
|
69 |
! !
|
|
70 |
|
|
71 |
!Plug methodsFor:'initialization'!
|
|
72 |
|
|
73 |
privateInitialize
|
|
74 |
"this method is NOT called initialize to allow plugging that
|
|
75 |
selector ..."
|
|
76 |
|
|
77 |
simulatedProtocol := IdentityDictionary new.
|
|
78 |
! !
|
|
79 |
|
|
80 |
Plug initialize!
|