Last active
September 11, 2017 01:18
-
-
Save genderquery/461b8f6e08bdc5ed6d8a1219cfb9fe55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { /* ... */ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (geometry instanceof Point) { | |
/* ... */ | |
} else if (geometry instanceof Multipoint) { | |
/* ... */ | |
} else if (geometry instanceof Polyline) { | |
/* ... */ | |
} else if (geometry instanceof Polygon) { | |
/* ... */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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