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,23 +5,19 @@ 5 5 } 6 6 7 7 type Circle struct { 8 - radiusfloat8 + length float 9 9 } 10 10 11 11 func Area(g GeometricObject) float { 12 - switch type(g): 13 - case Square: 14 - return g.length * g.length 12 + switch (g.type()): 15 15 case Circle: 16 - return PI * g.radius * g.radius 14 + return 15 + case Square: 16 + return ... 17 17 } 18 18 19 19 func Circumference(g GeometricObject) float { 20 - switch type(g): 21 - case Square: 22 - return 4 * g.length 23 - case Circle: 24 - return 2 * PI * g.radius 20 + ... 25 25 } 26 26 27 27 #### Object-Oriented Style