Wiki source code of Code Example: Data Structure Style vs. Object Style
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
2.1 | 1 | asd |
2 | |||
![]() |
1.1 | 3 | ``` |
![]() |
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 | |||
25 | asd |