" OO version for Smalltalk " " Paul H. Hargrove 2007.06.10 " " " " Some people claim Smalltalk allows one to take OO to ridiculous extremes. " " This program attempts to demonstrate that (with suitable self-ridicule). " " Excluding the comments, no method is longer than three 80-char lines. " " For aggressive code reuse, no string literal appears more than once. " " 99 bottles is the default, but other lengths can be specified at " " object instantiation. " " " " Written for and tested w/ GNU Smalltalk 2.3.5 " !Number methodsFor: 'drinking songs'! asBottles "String factory: turns bottle count into English" ^((self = 0) ifTrue: ['no more'] ifFalse: [self printString]), ' bottle', ((self = 1) ifTrue: [' '] ifFalse: ['s ']), 'of beer'. ! ! !String methodsFor: 'drinking songs'! initialUpper |s| "String factory: generates a copy with an initial capital" ^(s := (String withAll: self)) at: 1 put: (s first asUppercase); yourself. ! ! "Objects of class BeerSong are songs. Send asString to return the lyrics." Object subclass: #BeerSong instanceVariableNames: 'lyrics sizeOfWall bottleCount bottleString' classVariableNames: '' poolDictionaries: '' category: 'Drinking-Songs' ! ! !BeerSong class methodsFor: 'instantiation'! new "new: with default song length of 99 bottles" ^self new: 99. ! new: wallSizeInUnitsOfBottles ^super new initialize: wallSizeInUnitsOfBottles ! ! !BeerSong methodsFor: 'initialization'! initialize: aNumber "We generate the lyrics lazily when you show: them" "So initially we just set the ma