abstract class Shape {
abstract calculateArea(): number;
}
interface Drawable {
draw(): void;
}
class Circle extends Shape implements Drawable {
constructor(private radius: number) {
super();
}
calculateArea(): number {
return Math.PI * this.radius * this.radius;
}
draw(): void {
console.log(`绘制一个半径为 ${this.radius} 的圆`);
}
}
class Rectangle extends Shape implements Drawable {
constructor(private width: number, private height: number) {
super();
}
calculateArea(): number {
return this.width * this.height;
}
draw(): void {
console.log(`绘制一个宽为 ${this.width},高为 ${this.height} 的矩形`);
}
}