代码拉取完成,页面将自动刷新
同步操作将从 驯鹿者/ts_design_mode 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
enum ClothesTypeEnum {
Vest,
Shirt,
Jacket,
Hoodies,
Sweater
}
enum ColorEnum {
White,
Red,
Yellow,
Black
}
// 颜色的接口
interface ColorInterface {
getColor: () => void;
}
// 类型的抽象类
abstract class AbstractClothesClass {
protected color: ColorInterface;
public setColor(color: ColorInterface) {
this.color = color;
}
public abstract getClothes(): void;
}
//类型的扩充抽象类
class JacketProducer extends AbstractClothesClass {
public getClothes() {
let color = this.color.getColor();
console.log(color + "jacket");
}
}
class ShirtProducer extends AbstractClothesClass {
public getClothes() {
let color = this.color.getColor();
console.log(color + "shirt");
}
}
// 颜色的实现类;
class BlackColor implements ColorInterface {
public getColor() {
return "black";
}
}
class WhiteColor implements ColorInterface {
public getColor() {
return "white";
}
}
// 桥接具体实现类;
class CloseShop {
private static _instance: CloseShop;
public static getInstance() {
if (!this._instance) {
this._instance = new CloseShop();
}
return this._instance;
}
public getClothes(type: ClothesTypeEnum, color: ColorEnum) {
let clothes: AbstractClothesClass;
switch (type) {
case ClothesTypeEnum.Jacket:
clothes = new JacketProducer();
break;
case ClothesTypeEnum.Shirt:
clothes = new ShirtProducer();
break;
default:
throw new Error("not support type" + type);
}
switch (color) {
case ColorEnum.White:
clothes.setColor(new WhiteColor());
break;
case ColorEnum.Black:
clothes.setColor(new BlackColor());
break;
default:
throw new Error("not support color" + color);
}
return clothes;
}
}
const clothes = CloseShop.getInstance().getClothes(
ClothesTypeEnum.Shirt,
ColorEnum.Black
);
console.log(clothes);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。