Version 2.3 by chrisby on 2024/03/03 14:44

Hide last authors
chrisby 2.1 1 asd
2
chrisby 1.1 3 ```
chrisby 2.1 4 type Square struct {
5 length float
6 }
7
8 type Circle struct {
9 length float
10 }
11
12 func Area(g GeometricObject) float {
13 switch (g.type()):
14 case Circle:
15 return
16 case Square:
17 return ...
18 }
19
20 func Circumference(g GeometricObject) float {
21 ...
22 }
23 ```
24
chrisby 2.3 25 #### Object-Oriented Style
chrisby 2.2 26
chrisby 2.3 27 class Square {
28 length float
29
30 constructor(length float) {
31 this.length = length
32 }
33
34 func Area() float {
35 return this.length * this.length
36 }
37
38 func Circumference() float {
39 return 4 * this.length
40 }
41 }
42
43 class Circle {
44 radius float
45
46 constructor(radius float) {
47 this.radius = radius
48 }
49
50 func Area() float {
51 return PI * this.radius * this.radius
52 }
53
54 func Circumference() float {
55 return 2 * PI * this.radius
56 }
57 }