class Polygon { . . public int getPerimeter() {...} public boolean isConvex() {...} public boolean containsPoint(Point p) {...} . . }
我们可以把它改写成:
class Polygon { . . public int getPerimeter() {return pPolygon.computePerimeter(this);} public boolean isConvex() {return pPolygon.isConvex(this);} public boolean containsPoint(Point p) {return pPolygon.containsPoint(this, p);} . }
其中,pPolygon是:
class pPolygon { static public int computePerimeter(Polygon polygon) {...} static public boolean isConvex(Polygon polygon) {...}