author | Claus Gittinger <cg@exept.de> |
Fri, 26 Apr 1996 09:12:31 +0200 | |
changeset 226 | c5a265ceddd1 |
parent 224 | fe3164373601 |
child 228 | 8f73cdf66b60 |
permissions | -rw-r--r-- |
88 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
114
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
3 |
All Rights Reserved |
88 | 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 |
Model subclass:#Plug |
162 | 14 |
instanceVariableNames:'simulatedProtocol' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Objects' |
|
54 | 18 |
! |
19 |
||
20 |
!Plug class methodsFor:'documentation'! |
|
21 |
||
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
114
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
54 | 36 |
documentation |
37 |
" |
|
38 |
A Plug is an objcet which simulates a protocol and evaluates |
|
39 |
a corresponding block when receiving messages. |
|
226 | 40 |
Its main use is for the demo doIts, to play the role of a model, |
41 |
when no actual model class is available for the demo. |
|
224 | 42 |
|
43 |
[author:] |
|
44 |
Claus Gittinger |
|
54 | 45 |
" |
46 |
! |
|
47 |
||
48 |
examples |
|
49 |
" |
|
50 |
|plug| |
|
51 |
||
52 |
plug := Plug new. |
|
53 |
plug respondTo:#foo with:[Transcript showCr:'received foo']. |
|
54 |
plug respondTo:#foo: with:[:arg | Transcript showCr:'received foo: ', arg printString]. |
|
55 |
||
56 |
plug foo. |
|
57 |
plug foo:'some argument' |
|
162 | 58 |
|
59 |
||
60 |
simulating ``instance variables'': |
|
61 |
(actually, this is somewhat expensive - the contexts locals are used for them ...) |
|
62 |
be careful with unintended variable sharing (if plugs are created in a loop ..) |
|
63 |
||
64 |
|plug1 plug2 local1 local2| |
|
65 |
||
66 |
plug1 := Plug new. |
|
67 |
plug1 respondTo:#get with:[local1]. |
|
68 |
plug1 respondTo:#set: with:[:arg | local1 := arg]. |
|
69 |
||
70 |
plug2 := Plug new. |
|
71 |
plug2 respondTo:#get with:[local2]. |
|
72 |
plug2 respondTo:#set: with:[:arg | local2 := arg]. |
|
73 |
||
74 |
Transcript show:'plug1''s value: '; showCr:plug1 get. |
|
75 |
Transcript show:'plug2''s value: '; showCr:plug2 get. |
|
76 |
||
77 |
plug1 set:5. |
|
78 |
plug2 set:17. |
|
79 |
||
80 |
Transcript show:'plug1''s value: '; showCr:plug1 get. |
|
81 |
Transcript show:'plug2''s value: '; showCr:plug2 get. |
|
54 | 82 |
" |
83 |
! ! |
|
84 |
||
85 |
!Plug class methodsFor:'instance creation'! |
|
86 |
||
87 |
new |
|
88 |
^ super basicNew privateInitialize |
|
89 |
! ! |
|
90 |
||
137 | 91 |
!Plug methodsFor:'initialization'! |
92 |
||
93 |
privateInitialize |
|
94 |
"this method is NOT called initialize to allow plugging that |
|
95 |
selector ..." |
|
96 |
||
97 |
simulatedProtocol := IdentityDictionary new. |
|
98 |
! ! |
|
99 |
||
54 | 100 |
!Plug methodsFor:'message sending'! |
101 |
||
102 |
doesNotUnderstand:aMessage |
|
103 |
|block| |
|
104 |
||
105 |
block := simulatedProtocol at:aMessage selector ifAbsent:[]. |
|
106 |
block isNil ifTrue:[ |
|
82 | 107 |
^ super doesNotUnderstand:aMessage |
54 | 108 |
]. |
109 |
^ block valueWithArguments:(aMessage arguments) |
|
110 |
! ! |
|
111 |
||
137 | 112 |
!Plug methodsFor:'protocol definition'! |
113 |
||
114 |
respondTo:aSelector with:aBlock |
|
115 |
simulatedProtocol at:aSelector put:aBlock |
|
116 |
! ! |
|
117 |
||
82 | 118 |
!Plug methodsFor:'queries'! |
119 |
||
120 |
respondsTo:aSelector |
|
121 |
(simulatedProtocol includesKey:aSelector) ifTrue:[^ true]. |
|
122 |
^ super respondsTo:aSelector |
|
123 |
! ! |
|
124 |
||
137 | 125 |
!Plug class methodsFor:'documentation'! |
54 | 126 |
|
137 | 127 |
version |
226 | 128 |
^ '$Header: /cvs/stx/stx/libview2/Plug.st,v 1.10 1996-04-26 07:12:31 cg Exp $' |
54 | 129 |
! ! |