How to design shape class

Posted by Tomek Tarczynski on Stack Overflow See other posts from Stack Overflow or by Tomek Tarczynski
Published on 2010-04-10T19:10:46Z Indexed on 2010/04/10 19:13 UTC
Read the original article Hit count: 430

Filed under:
|
|
|

I want to design shape class. I need to distinguish several different shapes:

-Point  
-Line  
-Triangle  
-Circle  
-Polygons  

The main purpose of this class is to calculate distance between two shapes.
I've all methods for calculating those distances, but I want to have a single method that can be used, it should looks like this:

float Distance(Shape a, Shape b)

Simplest way to do it is to put a lot of if statements and then invoke proper method but this is deffinitely not OOP.

How to design such class in OOP style?

© Stack Overflow or respective owner

Related posts about shapes

Related posts about c#