I'm not sure about the switch approach described in the post:
function area(shape)
switch shape.type
case "square": return shape.side ** 2
case "circle": return 2 * PI * shape.radius
case "triangle": return ...
case "segment": return 0
case "polygon": return ...
...
case "oval": return ...
You can have a lot of cases, some of them requiring non trivial code...
Eventually you write a function for each case and it's more work than adding a method for each shape because you still need to write the switch...Classes seem work better than structures here.
But then you want to handle intersections
The switch approach doesn't seem realistic:
function intersection(shapeA, shapeB)
if(shapeA.type == "circle" AND shapeB.type == "circle")...
if(shapeA.type == "circle" AND shapeB.type == "square")...
if(shapeA.type == "square" AND shapeB.type == "circle")...
...//uh oh you have nShapes**2 cases to handle
But java classes or not better: where do you define Circle-Square intersection? In Circle? In Square?Even with multiple dispatch the solution is not ideal. You now have some things related to Circle (area, perimeter...) in the Circle.blub file, and intersection(Circle, Circle) wich only works with Circles is now in intersections.blub...
I don't see a good solution and sometimes I feel like the problem is more with our tools (code in text files) rather than programming paradigms