1.有稳定的整体操作结构,各个步骤却有改变的需求
2.灵活的实现各个步骤的变换(步骤总是有实现的先后关系)
例子:
abstract class cook { public docook() { this.buyrawmaterial(); this.clearmaterial(); this.cooking(); this.outpot(); this.clearpot(); } protected abstract buyrawmaterial(): void; protected abstract clearmaterial(); protected abstract cooking(): void; protected abstract outpot(): void; protected clearpot(): void{ console.log('锅是一定要刷的'); } } class huiguorou extends cook { protected buyrawmaterial() { console.log('买肉'); } protected clearmaterial() { console.log('肉和辣椒洗干净'); } protected cooking() { console.log('很复杂'); } protected outpot() { console.log('好了要出锅的'); } } class tangchupaigu extends cook { protected buyrawmaterial() { console.log('买排骨'); } protected clearmaterial() { console.log('排骨洗干净了'); } protected cooking() { console.log('很复杂,鬼知道怎么做的'); } protected outpot() { console.log('好了要出锅的'); } } class client { test() { console.log('今天吃啥'); let food: cook = new huiguorou(); food.docook(); let food2: cook = new tangchupaigu(); food2.docook(); } } new client().test();
如对本文有疑问, 点击进行留言回复!!
荐 微信小程序动态评分展示/五角星展示/半颗星展示/自定义长度展示
深入理解CSS background-blend-mode的作用机制
网友评论