1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class Point { x: number; y: number; private constructor(x: number, y: number) { this .x = x; this .y = y; } static Factory = class { static pointXY(x: number, y: number) { return new Point(x, y); } static pointPolar(r: number, theta: number) { return new Point( r * Math.cos((theta * Math.PI) / 180), r * Math.sin((theta * Math.PI) / 180) ); } }; } |
1 | const pt = Point.Factory.pointXY(10, 20); |
No comments:
Post a Comment