Consider the task:
- Read a polygon from a KML file using library A
- Intersect it with another polygon using library B
- Calculate its area using library C
Each library has it’s own Polygon class, and they are all equivalent. Which is the best practice when using all these classes? At the moment I first wrote this question I had implemented a method that converts a PolygonA instance into a PolygonB instance and vice-versa. But I wonder if it is the only way.
Clarification All libraries are third-parties’
One option that comes to mind is defining your own polygon class with copy constructors that accept the other types and methods on it to create instances of the other types from its data.
Doesn’t really offer much advantage over the methods you have. However, I prefer it since it standardizes on one definition of polygon and then convert to the others as needed. Alternatively just pick one of the existing implementations as your base and just write methods to go between it and the other two.