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