diff --git a/source/Buoy-Collections-Tests/CollectionFormatterTest.class.st b/source/Buoy-Collections-Tests/CollectionFormatterTest.class.st index 2efe7aa..9dea3de 100644 --- a/source/Buoy-Collections-Tests/CollectionFormatterTest.class.st +++ b/source/Buoy-Collections-Tests/CollectionFormatterTest.class.st @@ -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 +] diff --git a/source/Buoy-Collections/CollectionFormatter.class.st b/source/Buoy-Collections/CollectionFormatter.class.st index f83377a..312b78f 100644 --- a/source/Buoy-Collections/CollectionFormatter.class.st +++ b/source/Buoy-Collections/CollectionFormatter.class.st @@ -6,7 +6,7 @@ Implementation Notes: " Class { #name : 'CollectionFormatter', - #superclass : 'Object', + #superclass : 'Formatter', #instVars : [ 'separator', 'elementFormatter', @@ -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 [ diff --git a/source/Buoy-Collections/Formatter.class.st b/source/Buoy-Collections/Formatter.class.st new file mode 100644 index 0000000..07c346a --- /dev/null +++ b/source/Buoy-Collections/Formatter.class.st @@ -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 +]