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

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(){ /* ... */}
}
主站蜘蛛池模板: 金塔县| 石林| 方城县| 阿城市| 来安县| 广昌县| 商河县| 合肥市| 平原县| 荣成市| 阳新县| 罗江县| 北海市| 漳平市| 龙门县| 客服| 县级市| 肇庆市| 马边| 泰宁县| 长岛县| 札达县| 乳山市| 饶平县| 汽车| 如皋市| 石屏县| 买车| 霞浦县| 丁青县| 延川县| 兰坪| 石河子市| 枣庄市| 石首市| 福州市| 兴安盟| 通河县| 育儿| 天祝| 白水县|