官术网_书友最值得收藏!

Interface

As we start building complex apps, there will be a common need for a certain type of structure to be repeated throughout the app, which follows certain rules. This is where an interface comes into the picture. Interfaces provide structural subtyping or duck typing to check the type and shape of entities.

For instance, if we are working with an app that deals with cars, every car will have a certain common structure that needs to be adhered to when used within the app. Hence we create an interface named ICar. Any class working with cars will implement this interface as follows:

Interface ICar { 
engine : String;
color: String;
price : Number;
}

class CarInfo implements ICar{
engine : String;
color: String;
price : Number;

constructor(){ /* ... */}
}
主站蜘蛛池模板: 嘉鱼县| 大石桥市| 建瓯市| 东乡族自治县| 洪湖市| 梓潼县| 黔江区| 永福县| 郁南县| 长兴县| 阿拉善左旗| 灵丘县| 关岭| 清镇市| 万源市| 宜城市| 深州市| 武山县| 黔东| 清新县| 绥化市| 台南县| 光山县| 阿鲁科尔沁旗| 合作市| 桦甸市| 祁东县| 富平县| 白山市| 南召县| 弥渡县| 深泽县| 临朐县| 北海市| 老河口市| 百色市| 祁阳县| 敦煌市| 南投县| 长阳| 龙里县|