Appearance
桥接设计模式 / Bridge
桥接设计模式是一种设计模式,它允许你将抽象部分和实现部分分离,使它们可以独立地变化。
Code
javascript
class Shape {
constructor(color) {
this.color = color;
}
draw() {}
}
class Circle extends Shape {
constructor(color) {
super(color);
}
draw() {
console.log(`Drawing a circle with ${this.color} color`);
}
}
class Square extends Shape {
constructor(color) {
super(color);
}
draw() {
console.log(`Drawing a square with ${this.color} color`);
}
}