-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgrammingLanguages.st
More file actions
89 lines (58 loc) · 1.78 KB
/
Copy pathProgrammingLanguages.st
File metadata and controls
89 lines (58 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'From VisualWorks® Personal Use Edition, 7.9.1 of October 18, 2012 on October 30, 2022 at 9:13:37 PM'!
CodeComponent create: #package named: 'ProgrammingLanguages'!"Package ProgrammingLanguages*"!
CodeComponent create: #package named: 'ProgrammingLanguages'!
Smalltalk defineClass: #Polygon
superclass: #{Core.Object}
indexedType: #none
private: false
instanceVariableNames: 'vertices name '
classInstanceVariableNames: ''
imports: ''
category: 'ProgrammingLanguages'!
Polygon comment:
'Generic polygon class with the first vertex in (0,0)
Instance Variables
name <MessageForwarder | Object | ProtoObject | ProtoObject> description of name
vertices <(Array of: Point)> description of vertices
'!
Smalltalk defineClass: #Square
superclass: #{Smalltalk.Polygon}
indexedType: #none
private: false
instanceVariableNames: ''
classInstanceVariableNames: ''
imports: ''
category: 'ProgrammingLanguages'!
Square comment:
'A square with its first vertex in (0,0)
'!
!Polygon methodsFor: 'initialize-release'!
initialize: numberOfVertices name: newName
"object constructor"
name:=newName.
vertices:=Array new: numberOfVertices.
vertices at: 1 put: 0@0.! !
!Polygon methodsFor: 'accessing'!
name: new_name
"sets new name of the polygon"
name:=new_name!
name
"gets polygon name"
^name! !
!Square methodsFor: 'actions'!
area
"compute area of the square"
^(vertices at: 2) x squared! !
!Square methodsFor: 'arithmetic'!
+ figure
"add 2 figures by adding there areas"
| a |
a:=self area + figure area.
^(Square new) initialize: a sqrt! !
!Square methodsFor: 'initialize-release'!
initialize: side
"create a square of the given side length"
super initialize: 4 name: 'Square'.
vertices at: 2 put: side@0.
vertices at: 3 put: side@side.
vertices at: 4 put: 0@side.! !