tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
75
Task/Polymorphism/Smalltalk/polymorphism.st
Normal file
75
Task/Polymorphism/Smalltalk/polymorphism.st
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
!Object subclass: #Point
|
||||
instanceVariableNames: 'x y'
|
||||
classVariableNames: ''
|
||||
poolDictionaries: ''
|
||||
category: 'polymorphism' !
|
||||
|
||||
!Point class methodsFor: 'instance creation'!
|
||||
new
|
||||
^self newBasic x := 0; y := 0 ! !
|
||||
|
||||
!Point class methodsFor: 'instance creation'!
|
||||
x: x y: y
|
||||
^self newBasic x := x; y := y ! !
|
||||
|
||||
!Point methodsFor: 'member access'!
|
||||
x
|
||||
^x ! !
|
||||
|
||||
!Point methodsFor: 'member access'!
|
||||
y
|
||||
^y ! !
|
||||
|
||||
!Point methodsFor: 'member access'!
|
||||
x: x
|
||||
^self x := x ! !
|
||||
|
||||
!Point methodsFor: 'member access'!
|
||||
y: y
|
||||
^self y := y ! !
|
||||
|
||||
!Point methodsFor: 'member access'!
|
||||
x: x y: y
|
||||
^self x := x; y := y ! !
|
||||
|
||||
!Point methodsFor: 'polymorphism test'!
|
||||
print
|
||||
Transcript show: x; space; show: y ! !
|
||||
|
||||
!Object subclass: #Circle
|
||||
instanceVariableNames: 'center r'
|
||||
classVariableNames: ''
|
||||
poolDictionaries: ''
|
||||
category: 'polymorphism' !
|
||||
|
||||
!Circle class methodsFor: 'instance creation'!
|
||||
new
|
||||
^self newBasic center := Point new; r := 0 ! !
|
||||
|
||||
!Circle class methodsFor: 'instance creation'!
|
||||
radius: radius
|
||||
^self newBasic center := Point new; r := radius ! !
|
||||
|
||||
!Circle class methodsFor: 'instance creation'!
|
||||
at: point radius: r
|
||||
^self newBasic center := point; r := r ! !
|
||||
|
||||
!Circle methodsFor: 'member access'!
|
||||
center
|
||||
^center ! !
|
||||
|
||||
!Circle methodsFor: 'member access'!
|
||||
x: x y: y
|
||||
^self center x: x y: y ! !
|
||||
|
||||
!Circle methodsFor: 'member access'!
|
||||
radius
|
||||
^r ! !
|
||||
|
||||
!Circle methodsFor: 'member access'!
|
||||
radius: radius
|
||||
^self r := radius ! !
|
||||
|
||||
!Circle methodsFor: 'polymorphism test'!
|
||||
print
|
||||
Transcript show: center; space; show: radius ! !
|
||||
Loading…
Add table
Add a link
Reference in a new issue