Plug.st
author tz
Sat, 07 Feb 1998 16:57:39 +0100
changeset 834 ac1655bd31bb
parent 444 4ad5cc26ad6a
child 1317 18aabf275ec2
permissions -rw-r--r--
class category changed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
claus
parents: 82
diff changeset
     1
"
claus
parents: 82
diff changeset
     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
claus
parents: 82
diff changeset
     4
claus
parents: 82
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 82
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 82
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 82
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 82
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 82
diff changeset
    10
 hereby transferred.
claus
parents: 82
diff changeset
    11
"
claus
parents: 82
diff changeset
    12
55
409211feffa2 *** empty log message ***
claus
parents: 54
diff changeset
    13
Model subclass:#Plug
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    14
	instanceVariableNames:'simulatedProtocol'
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    15
	classVariableNames:''
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    16
	poolDictionaries:''
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    17
	category:'Kernel-Objects'
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    18
!
f8592e95890f Initial revision
claus
parents:
diff changeset
    19
f8592e95890f Initial revision
claus
parents:
diff changeset
    20
!Plug class methodsFor:'documentation'!
f8592e95890f Initial revision
claus
parents:
diff changeset
    21
88
claus
parents: 82
diff changeset
    22
copyright
claus
parents: 82
diff changeset
    23
"
claus
parents: 82
diff changeset
    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
claus
parents: 82
diff changeset
    26
claus
parents: 82
diff changeset
    27
 This software is furnished under a license and may be used
claus
parents: 82
diff changeset
    28
 only in accordance with the terms of that license and with the
claus
parents: 82
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
claus
parents: 82
diff changeset
    30
 be provided or otherwise made available to, or used by, any
claus
parents: 82
diff changeset
    31
 other person.  No title to or ownership of the software is
claus
parents: 82
diff changeset
    32
 hereby transferred.
claus
parents: 82
diff changeset
    33
"
claus
parents: 82
diff changeset
    34
!
claus
parents: 82
diff changeset
    35
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    36
documentation
f8592e95890f Initial revision
claus
parents:
diff changeset
    37
"
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    38
    A Plug is an object which simulates a protocol and evaluates
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    39
    a corresponding block when receiving messages.
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    40
    A plugs interface can be changed dynamically.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    41
226
c5a265ceddd1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 224
diff changeset
    42
    Its main use is for the demo doIts, to play the role of a model,
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    43
    when no actual modelClass is available for the demonstration.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    44
    However, it can be used wherever some object is needed which responds to
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    45
    some protocol AND you do not want to add a class for it
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    46
    (lightWeight objects).
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    47
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    48
    There is a slight performance penalty - compared to `normal' objects,
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    49
    getting `normal' messages, though.
224
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    50
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    51
    [author:]
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    52
        Claus Gittinger
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    53
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    54
    [see also:]
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    55
        Model
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    56
"
f8592e95890f Initial revision
claus
parents:
diff changeset
    57
!
f8592e95890f Initial revision
claus
parents:
diff changeset
    58
f8592e95890f Initial revision
claus
parents:
diff changeset
    59
examples
f8592e95890f Initial revision
claus
parents:
diff changeset
    60
"
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    61
                                                                        [exBegin]
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    62
    |plug|
f8592e95890f Initial revision
claus
parents:
diff changeset
    63
f8592e95890f Initial revision
claus
parents:
diff changeset
    64
    plug := Plug new.
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
    65
    plug respondTo:#foo  with:[Transcript showCR:'received foo'].
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
    66
    plug respondTo:#foo: with:[:arg | Transcript showCR:'received foo: ', arg printString].
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    67
f8592e95890f Initial revision
claus
parents:
diff changeset
    68
    plug foo.
f8592e95890f Initial revision
claus
parents:
diff changeset
    69
    plug foo:'some argument'
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    70
                                                                        [exEnd]
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    71
360
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    72
  using a plug as a generator (simulates a readStream):
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    73
                                                                        [exBegin]
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    74
    |generator num|
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    75
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    76
    num := 0.
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    77
    generator := Plug new.
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    78
    generator respondTo:#next
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    79
                   with:[num := num + 1. num].
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    80
    generator respondTo:#atEnd
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    81
                   with:[false].
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    82
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    83
    10 timesRepeat:[
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    84
        Transcript showCR:(generator next)
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    85
    ]
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    86
                                                                        [exEnd]
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    87
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    88
  simulating ``instance variables'':
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    89
  (actually, this is somewhat expensive - the contexts locals are used for them ...)
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    90
  be careful with unintended variable sharing (if plugs are created in a loop ..)
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    91
                                                                        [exBegin]
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    92
    |plug1 plug2 local1 local2|
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    93
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    94
    plug1 := Plug new.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    95
    plug1 respondTo:#get  with:[local1].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    96
    plug1 respondTo:#set: with:[:arg | local1 := arg].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    97
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    98
    plug2 := Plug new.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    99
    plug2 respondTo:#get  with:[local2].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   100
    plug2 respondTo:#set: with:[:arg | local2 := arg].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   101
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   102
    Transcript show:'plug1''s value: '; showCR:plug1 get.
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   103
    Transcript show:'plug2''s value: '; showCR:plug2 get.
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   104
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   105
    plug1 set:5.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   106
    plug2 set:17.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   107
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   108
    Transcript show:'plug1''s value: '; showCR:plug1 get.
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   109
    Transcript show:'plug2''s value: '; showCR:plug2 get.
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   110
                                                                        [exEnd]
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   111
"
f8592e95890f Initial revision
claus
parents:
diff changeset
   112
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   113
f8592e95890f Initial revision
claus
parents:
diff changeset
   114
!Plug class methodsFor:'instance creation'!
f8592e95890f Initial revision
claus
parents:
diff changeset
   115
f8592e95890f Initial revision
claus
parents:
diff changeset
   116
new
232
b898f5762952 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
   117
    ^ super basicNew privateInitialize
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   118
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   119
    "Modified: 27.4.1996 / 16:16:59 / cg"
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   120
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   121
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   122
!Plug methodsFor:'initialization'!
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   123
232
b898f5762952 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
   124
privateInitialize
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   125
    "this method is NOT called `#initialize' to allow plugging that
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   126
     selector ..."
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   127
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   128
    simulatedProtocol := IdentityDictionary new.
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   129
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   130
    "Modified: 27.4.1996 / 16:15:45 / cg"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   131
    "Created: 27.4.1996 / 16:17:07 / cg"
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   132
! !
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   133
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   134
!Plug methodsFor:'message sending'!
f8592e95890f Initial revision
claus
parents:
diff changeset
   135
f8592e95890f Initial revision
claus
parents:
diff changeset
   136
doesNotUnderstand:aMessage
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   137
    "catch unhandled messages by looking in my simulated protocol
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   138
     definition; if there is some block for it, return its value.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   139
     Otherwise, fall into the real doesNotUnderstand error."
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   140
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   141
    |block|
f8592e95890f Initial revision
claus
parents:
diff changeset
   142
f8592e95890f Initial revision
claus
parents:
diff changeset
   143
    block := simulatedProtocol at:aMessage selector ifAbsent:[].
f8592e95890f Initial revision
claus
parents:
diff changeset
   144
    block isNil ifTrue:[
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   145
        ^ super doesNotUnderstand:aMessage
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   146
    ].
f8592e95890f Initial revision
claus
parents:
diff changeset
   147
    ^ block valueWithArguments:(aMessage arguments)
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   148
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   149
    "Modified: 27.4.1996 / 16:15:34 / cg"
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   150
!
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   151
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   152
value
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   153
    "catch this one - its so common"
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   154
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   155
    ^ self doesNotUnderstand:(Message selector:#value arguments:#())
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   156
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   157
    "Created: 21.1.1997 / 15:21:24 / cg"
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   158
!
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   159
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   160
value:arg
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   161
    "catch this one - its so common"
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   162
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   163
    ^ self doesNotUnderstand:(Message selector:#value: argument:arg)
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   164
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   165
    "Created: 21.1.1997 / 15:21:36 / cg"
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   166
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   167
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   168
!Plug methodsFor:'protocol definition'!
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   169
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   170
forgetAbout:aSelector
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   171
    "tell the receiver to forget about how to respond to the given by selector"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   172
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   173
    simulatedProtocol removeKey:aSelector ifAbsent:nil
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   174
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   175
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   176
     |p|
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   177
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   178
     p := Plug new.
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   179
     p respondTo:#foo  with:[Transcript showCR:'foo'].
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   180
     p respondTo:#foo: with:[:arg | Transcript show:'foo:'; showCR:arg].
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   181
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   182
     p foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   183
     p foo:'hello'.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   184
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   185
     p forgetAbout:#foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   186
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   187
     p foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   188
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   189
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   190
    "Modified: 27.4.1996 / 16:14:19 / cg"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   191
    "Created: 27.4.1996 / 16:19:08 / cg"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   192
!
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   193
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   194
respondTo:aSelector with:aBlock
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   195
    "tell the receiver to respond to a message given by selector,
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   196
     with evaluating aBlock. The number of arguments as defined by the 
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   197
     selector must match the number of blockArsg expected by the block.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   198
     The value returned from aBlock will be the value returned from the
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   199
     message."
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   200
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   201
    (self class implements:aSelector) ifFalse:[
444
4ad5cc26ad6a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   202
        (self class superclass canUnderstand:aSelector) ifTrue:[
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   203
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   204
            "/ sorry - this implementation is too quick of a hack.
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   205
            "/ (must be rewritten to inherit from nil, in order 
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   206
            "/  to be able to catch more ...)
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   207
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   208
            self error:'inherited message cannot be redefined: ' , aSelector.
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   209
        ]
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   210
    ].
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   211
    simulatedProtocol at:aSelector put:aBlock
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   212
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   213
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   214
     |p|
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   215
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   216
     p := Plug new.
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   217
     p respondTo:#foo  with:[Transcript showCR:'foo'].
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   218
     p respondTo:#foo: with:[:arg | Transcript show:'foo:'; showCR:arg].
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   219
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   220
     p foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   221
     p foo:'hello'
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   222
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   223
444
4ad5cc26ad6a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   224
    "Modified: 21.2.1997 / 18:35:07 / cg"
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   225
! !
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   226
82
claus
parents: 55
diff changeset
   227
!Plug methodsFor:'queries'!
claus
parents: 55
diff changeset
   228
claus
parents: 55
diff changeset
   229
respondsTo:aSelector
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   230
    "return true, if the receiver responds to a message"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   231
82
claus
parents: 55
diff changeset
   232
    (simulatedProtocol includesKey:aSelector) ifTrue:[^ true].
claus
parents: 55
diff changeset
   233
    ^ super respondsTo:aSelector
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   234
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   235
    "Modified: 27.4.1996 / 16:14:41 / cg"
82
claus
parents: 55
diff changeset
   236
! !
claus
parents: 55
diff changeset
   237
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   238
!Plug class methodsFor:'documentation'!
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   239
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   240
version
444
4ad5cc26ad6a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   241
    ^ '$Header: /cvs/stx/stx/libview2/Plug.st,v 1.16 1997-02-21 19:38:32 cg Exp $'
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   242
! !