88
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
55
|
13 |
'From Smalltalk/X, Version:2.10.5 on 26-mar-1995 at 4:21:12 am'!
|
54
|
14 |
|
55
|
15 |
Model subclass:#Plug
|
54
|
16 |
instanceVariableNames:'simulatedProtocol'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Kernel-Objects'
|
|
20 |
!
|
|
21 |
|
|
22 |
!Plug class methodsFor:'documentation'!
|
|
23 |
|
88
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
54
|
38 |
version
|
|
39 |
"
|
96
|
40 |
$Header: /cvs/stx/stx/libview2/Plug.st,v 1.5 1995-08-29 17:44:29 claus Exp $
|
54
|
41 |
"
|
|
42 |
!
|
|
43 |
|
|
44 |
documentation
|
|
45 |
"
|
|
46 |
A Plug is an objcet which simulates a protocol and evaluates
|
|
47 |
a corresponding block when receiving messages.
|
|
48 |
Its main use is for the demo doIts, to play the role of a model.
|
|
49 |
Plugs are not used in the system and exist as a demo only.
|
|
50 |
This class may be changed/removed/replaced without notice.
|
|
51 |
"
|
|
52 |
!
|
|
53 |
|
|
54 |
examples
|
|
55 |
"
|
|
56 |
|plug|
|
|
57 |
|
|
58 |
plug := Plug new.
|
|
59 |
plug respondTo:#foo with:[Transcript showCr:'received foo'].
|
|
60 |
plug respondTo:#foo: with:[:arg | Transcript showCr:'received foo: ', arg printString].
|
|
61 |
|
|
62 |
plug foo.
|
|
63 |
plug foo:'some argument'
|
|
64 |
"
|
|
65 |
! !
|
|
66 |
|
|
67 |
!Plug class methodsFor:'instance creation'!
|
|
68 |
|
|
69 |
new
|
|
70 |
^ super basicNew privateInitialize
|
|
71 |
! !
|
|
72 |
|
|
73 |
!Plug methodsFor:'message sending'!
|
|
74 |
|
|
75 |
doesNotUnderstand:aMessage
|
|
76 |
|block|
|
|
77 |
|
|
78 |
block := simulatedProtocol at:aMessage selector ifAbsent:[].
|
|
79 |
block isNil ifTrue:[
|
82
|
80 |
^ super doesNotUnderstand:aMessage
|
54
|
81 |
].
|
|
82 |
^ block valueWithArguments:(aMessage arguments)
|
|
83 |
! !
|
|
84 |
|
82
|
85 |
!Plug methodsFor:'queries'!
|
|
86 |
|
|
87 |
respondsTo:aSelector
|
|
88 |
(simulatedProtocol includesKey:aSelector) ifTrue:[^ true].
|
|
89 |
^ super respondsTo:aSelector
|
|
90 |
! !
|
|
91 |
|
55
|
92 |
!Plug methodsFor:'protocol definition'!
|
|
93 |
|
|
94 |
respondTo:aSelector with:aBlock
|
|
95 |
simulatedProtocol at:aSelector put:aBlock
|
|
96 |
! !
|
|
97 |
|
54
|
98 |
!Plug methodsFor:'initialization'!
|
|
99 |
|
|
100 |
privateInitialize
|
|
101 |
"this method is NOT called initialize to allow plugging that
|
|
102 |
selector ..."
|
|
103 |
|
|
104 |
simulatedProtocol := IdentityDictionary new.
|
|
105 |
! !
|
|
106 |
|