From bf11813e4fa859a4833cab226c4ea560765d6d77 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 23 Nov 2025 17:01:59 +0100 Subject: Add ReDo Pharo excercises --- pharo-mooc/redo/src/MyCounter/Counter.class.st | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pharo-mooc/redo/src/MyCounter/Counter.class.st (limited to 'pharo-mooc/redo/src/MyCounter/Counter.class.st') diff --git a/pharo-mooc/redo/src/MyCounter/Counter.class.st b/pharo-mooc/redo/src/MyCounter/Counter.class.st new file mode 100644 index 0000000..2d65fa1 --- /dev/null +++ b/pharo-mooc/redo/src/MyCounter/Counter.class.st @@ -0,0 +1,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 +] -- cgit v1.2.3