Plug.st
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--
checkin from browser
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
"
f8592e95890f Initial revision
claus
parents:
diff changeset
    38
    A Plug is an objcet which simulates a protocol and evaluates
f8592e95890f Initial revision
claus
parents:
diff changeset
    39
    a corresponding block when receiving messages.
226
c5a265ceddd1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 224
diff changeset
    40
    Its main use is for the demo doIts, to play the role of a model,
c5a265ceddd1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 224
diff changeset
    41
    when no actual model class is available for the demo.
224
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    42
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    43
    [author:]
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    44
        Claus Gittinger
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    45
"
f8592e95890f Initial revision
claus
parents:
diff changeset
    46
!
f8592e95890f Initial revision
claus
parents:
diff changeset
    47
f8592e95890f Initial revision
claus
parents:
diff changeset
    48
examples
f8592e95890f Initial revision
claus
parents:
diff changeset
    49
"
f8592e95890f Initial revision
claus
parents:
diff changeset
    50
    |plug|
f8592e95890f Initial revision
claus
parents:
diff changeset
    51
f8592e95890f Initial revision
claus
parents:
diff changeset
    52
    plug := Plug new.
f8592e95890f Initial revision
claus
parents:
diff changeset
    53
    plug respondTo:#foo  with:[Transcript showCr:'received foo'].
f8592e95890f Initial revision
claus
parents:
diff changeset
    54
    plug respondTo:#foo: with:[:arg | Transcript showCr:'received foo: ', arg printString].
f8592e95890f Initial revision
claus
parents:
diff changeset
    55
f8592e95890f Initial revision
claus
parents:
diff changeset
    56
    plug foo.
f8592e95890f Initial revision
claus
parents:
diff changeset
    57
    plug foo:'some argument'
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    58
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    59
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    60
  simulating ``instance variables'':
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    61
  (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
    62
  be careful with unintended variable sharing (if plugs are created in a loop ..)
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    63
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    64
    |plug1 plug2 local1 local2|
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    65
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    66
    plug1 := Plug new.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    67
    plug1 respondTo:#get  with:[local1].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    68
    plug1 respondTo:#set: with:[:arg | local1 := arg].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    69
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    70
    plug2 := Plug new.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    71
    plug2 respondTo:#get  with:[local2].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    72
    plug2 respondTo:#set: with:[:arg | local2 := arg].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    73
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    74
    Transcript show:'plug1''s value: '; showCr:plug1 get.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    75
    Transcript show:'plug2''s value: '; showCr:plug2 get.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    76
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    77
    plug1 set:5.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    78
    plug2 set:17.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    79
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    80
    Transcript show:'plug1''s value: '; showCr:plug1 get.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    81
    Transcript show:'plug2''s value: '; showCr:plug2 get.
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    82
"
f8592e95890f Initial revision
claus
parents:
diff changeset
    83
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
    84
f8592e95890f Initial revision
claus
parents:
diff changeset
    85
!Plug class methodsFor:'instance creation'!
f8592e95890f Initial revision
claus
parents:
diff changeset
    86
f8592e95890f Initial revision
claus
parents:
diff changeset
    87
new
f8592e95890f Initial revision
claus
parents:
diff changeset
    88
    ^ super basicNew privateInitialize
f8592e95890f Initial revision
claus
parents:
diff changeset
    89
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
    90
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    91
!Plug methodsFor:'initialization'!
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    92
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    93
privateInitialize
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    94
    "this method is NOT called initialize to allow plugging that
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    95
     selector ..."
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    96
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    97
    simulatedProtocol := IdentityDictionary new.
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    98
! !
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    99
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   100
!Plug methodsFor:'message sending'!
f8592e95890f Initial revision
claus
parents:
diff changeset
   101
f8592e95890f Initial revision
claus
parents:
diff changeset
   102
doesNotUnderstand:aMessage
f8592e95890f Initial revision
claus
parents:
diff changeset
   103
    |block|
f8592e95890f Initial revision
claus
parents:
diff changeset
   104
f8592e95890f Initial revision
claus
parents:
diff changeset
   105
    block := simulatedProtocol at:aMessage selector ifAbsent:[].
f8592e95890f Initial revision
claus
parents:
diff changeset
   106
    block isNil ifTrue:[
82
claus
parents: 55
diff changeset
   107
	^ super doesNotUnderstand:aMessage
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   108
    ].
f8592e95890f Initial revision
claus
parents:
diff changeset
   109
    ^ block valueWithArguments:(aMessage arguments)
f8592e95890f Initial revision
claus
parents:
diff changeset
   110
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   111
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   112
!Plug methodsFor:'protocol definition'!
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   113
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   114
respondTo:aSelector with:aBlock
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   115
    simulatedProtocol at:aSelector put:aBlock
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   116
! !
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   117
82
claus
parents: 55
diff changeset
   118
!Plug methodsFor:'queries'!
claus
parents: 55
diff changeset
   119
claus
parents: 55
diff changeset
   120
respondsTo:aSelector
claus
parents: 55
diff changeset
   121
    (simulatedProtocol includesKey:aSelector) ifTrue:[^ true].
claus
parents: 55
diff changeset
   122
    ^ super respondsTo:aSelector
claus
parents: 55
diff changeset
   123
! !
claus
parents: 55
diff changeset
   124
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   125
!Plug class methodsFor:'documentation'!
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   126
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   127
version
226
c5a265ceddd1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 224
diff changeset
   128
    ^ '$Header: /cvs/stx/stx/libview2/Plug.st,v 1.10 1996-04-26 07:12:31 cg Exp $'
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   129
! !