typescript的class结合接口(interface)的简单使用

1、接口间继承extends

2、类结合接口使用implements

interface Radio{
    switchRadio(trigger:boolean):void
}
interface Battery{
    checkBatteryStatus():void
}
//接口继承extends
interface RadioWithBattery extends Radio{
    checkBatteryStatus():void
}
//接口接合类implements
class Cellphone implements Radio{
    switchRadio(trigger:boolean){}
}
//接口接合类implements
class Cellphone2 implements RadioWithBattery{
    switchRadio(trigger:boolean){}
    checkBatteryStatus(){}
} 

猜你喜欢

转载自blog.csdn.net/u011200562/article/details/125100595