Skip to content

Instantly share code, notes, and snippets.

@genderquery
Last active September 11, 2017 01:18
Show Gist options
  • Save genderquery/461b8f6e08bdc5ed6d8a1219cfb9fe55 to your computer and use it in GitHub Desktop.
Save genderquery/461b8f6e08bdc5ed6d8a1219cfb9fe55 to your computer and use it in GitHub Desktop.
enum GeometryType { POINT, MULTIPOINT, POLYLINE, POLYGON }
abstract class Geometry {
GeometryType geometryType;
Geometry(GeometryType geometryType) {
this.geometryType = geometryType;
}
}
class Point extends Geometry {
double x;
double y;
Point(double x, double y) {
super(GeometryType.POINT);
this.x = x;
this.y = y;
}
}
class Multipoint extends Geometry { /* ... */ }
class Polyline extends Geometry { /* ... */ }
class Polygon extends Geometry { /* ... */ }
if (geometry instanceof Point) {
/* ... */
} else if (geometry instanceof Multipoint) {
/* ... */
} else if (geometry instanceof Polyline) {
/* ... */
} else if (geometry instanceof Polygon) {
/* ... */
}
switch (geometry.geometryType) {
case POINT:
/* ... */
break;
case MULTIPOINT:
/* ... */
break;
case POLYLINE:
/* ... */
break;
case POLYGON:
/* ... */
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment