" CS 1621 Fall 2005 Demonstration of inheritance and polymorphic access in Smalltalk Note how easy it is to mix types and access them in a polymorphic way. " | s p flag type value | People := Dictionary new. flag := Prompter prompt: 'Read more data? (y/n)' default: ''. [flag = 'y'] whileTrue: [ "Here we are reading in the class name from the user. We must save it as a symbol, then access the Smalltalk dictionary at that key to obtain the actual class. Once we have the class we can create a new instance of the class using the default constructor." type := (Prompter prompt: 'Class type?' default: '') asSymbol. type := Smalltalk at: type. p := type new. p getData. "Call getData method" People at: (p name) put: p. "Use name as the key" p printString printNl. flag := Prompter prompt: 'Read more data? (y/n)' default: ''. ]. "Try different fields here for sorting. In particular, try a field that only exists in Student with a collection containing only Students, then try it on a collection containing some Persons as well" s := (Prompter prompt: 'Field to sort on?' default: '') asSymbol. p := SortedCollection sortBlock: [:a :b | (a perform: s) < (b perform: s)]. People do: [ :x | p add: x]. p do: [:x | (x printString) printNl. '' printNl]. !