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

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(){ /* ... */}
}
主站蜘蛛池模板: 嵩明县| 施秉县| 宁武县| 津南区| 双城市| 平邑县| 深圳市| 祥云县| 南投市| 岫岩| 容城县| 田林县| 安陆市| 安仁县| 登封市| 筠连县| 黄石市| 海阳市| 赤峰市| 江达县| 荆州市| 蛟河市| 哈密市| 永宁县| 兴文县| 无棣县| 商城县| 正蓝旗| 丹寨县| 溧阳市| 商南县| 望江县| 改则县| 潞城市| 青州市| 江华| 靖江市| 大渡口区| 黔西| 商城县| 天峨县|