Changes for page Code Example: Data Structure Style vs. Object Style
Last modified by chrisby on 2024/03/03 17:01
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -5,19 +5,23 @@ 5 5 } 6 6 7 7 type Circle struct { 8 - lengthfloat8 + radius float 9 9 } 10 10 11 11 func Area(g GeometricObject) float { 12 - switch (g.type()): 13 - case Circle: 14 - return 12 + switch type(g): 15 15 case Square: 16 - return ... 14 + return g.length * g.length 15 + case Circle: 16 + return PI * g.radius * g.radius 17 17 } 18 18 19 19 func Circumference(g GeometricObject) float { 20 - ... 20 + switch type(g): 21 + case Square: 22 + return 4 * g.length 23 + case Circle: 24 + return 2 * PI * g.radius 21 21 } 22 22 23 23 #### Object-Oriented Style