blob: 2d65fa1e901d647c6fddb0d806b8715db757c41c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
"
Counter is a simple concrete class which supports incrementing and
decrementing a counter.
Its API is
- decrement, increment
- count
Its creation API is message startingAt:
"
Class {
#name : #Counter,
#superclass : #Object,
#instVars : [
'count'
],
#category : #MyCounter
}
{ #category : #accessing }
Counter class >> startingAt: anInteger [
^ self new count: anInteger
]
{ #category : #accessing }
Counter >> count [
^ count
]
{ #category : #accessing }
Counter >> count: anInteger [
count := anInteger
]
{ #category : #operation }
Counter >> decrement [
count := count - 1
]
{ #category : #operation }
Counter >> increment [
count := count + 1
]
{ #category : #initialization }
Counter >> initialize [
super initialize.
count := 0
]
{ #category : #accessing }
Counter >> printOn: aStream [
super printOn: aStream. "a Counter"
aStream nextPutAll: ' withValue: ', count printString.
aStream cr
]
|