Introduction to OOP: Chapter 14 : Polymorphism [next] [previous] [audio] [real] [text]

Polymorphism in untyped languages

Polymorphism deals with types, and is thus a trivial issue in untyped languages, where all variables are potentially polymorphic.

silly: x
	" a silly smalltalk polymorphic method "
	(x isKindOf: Integer) ifTrue: [ ^ x + 1 ].
	(x isKindOf: Fraction) ifTrue: [ ^ x reciprocal ].
	(x isKindOf: String) ifTrue: [ ^ x reversed ].
	^ nil
Intro OOP, Chapter 14, Slide 4