Skip to content

Commit

Permalink
Add Formatter abstract superclass (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli authored Nov 19, 2024
1 parent 89936c7 commit b9998a7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ CollectionFormatterTest >> testFormatWithLastSeparator [
formatter := CollectionFormatter separatingWith: ', ' andLastWith: ' and '.
self assert: (formatter format: #(1 2 3)) equals: '1, 2 and 3'
]

{ #category : 'tests' }
CollectionFormatterTest >> testIsAbstract [

self deny: CollectionFormatter isAbstract
]
8 changes: 1 addition & 7 deletions source/Buoy-Collections/CollectionFormatter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Implementation Notes:
"
Class {
#name : 'CollectionFormatter',
#superclass : 'Object',
#superclass : 'Formatter',
#instVars : [
'separator',
'elementFormatter',
Expand Down Expand Up @@ -61,12 +61,6 @@ CollectionFormatter class >> separatingWith: aSeparator applyingToEach: anElemen
applyingToEach: anElementFormatter
]

{ #category : 'formatting' }
CollectionFormatter >> format: aCollection [

^ String streamContents: [ :stream | self format: aCollection on: stream ]
]

{ #category : 'formatting' }
CollectionFormatter >> format: aCollection on: aStream [

Expand Down
29 changes: 29 additions & 0 deletions source/Buoy-Collections/Formatter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"
I'm an abstract class for formatters.
A formatter is an object that knows how to convert a given object into a string representation.
"
Class {
#name : 'Formatter',
#superclass : 'Object',
#category : 'Buoy-Collections',
#package : 'Buoy-Collections'
}

{ #category : 'testing' }
Formatter class >> isAbstract [

^ self = Formatter
]

{ #category : 'formatting' }
Formatter >> format: aCollection [

^ String streamContents: [ :stream | self format: aCollection on: stream ]
]

{ #category : 'formatting' }
Formatter >> format: object on: stream [

self subclassResponsibility
]

0 comments on commit b9998a7

Please sign in to comment.