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

Class type interfaces

Class type interfaces define the contract for classes. A class that implements an interface should meet the requirement of the interface:

interface CustomerInterface { 
    id: number; 
    firstName: string; 
    lastName: string; 
    addCustomer(firstName: string, lastName: string); 
    getCustomer(id: number): Customer; 
} 
  
class Customer implements CustomerInterface { 
    id: number; 
    firstName: string; 
    lastName: string; 
    constructor() { } 
    addCustomer(firstName: string, lastName: string) { 
        // code to add customer 
   } 
    getCustomer(id: number): Customer { 
        return this; 
    } 
} 

The class type interface only deals with public members of the class. So, it is not possible to add private members to the interface.

主站蜘蛛池模板: 兴义市| 永泰县| 台前县| 镇平县| 恭城| 三门县| 陆川县| 红原县| 翁牛特旗| 龙南县| 甘孜县| 弥勒县| 彭阳县| 呈贡县| 都安| 青河县| 宁河县| 丰宁| 航空| 盐边县| 湘乡市| 吴川市| 将乐县| 罗源县| 巴彦淖尔市| 昆明市| 浦江县| 海晏县| 蓝山县| 临西县| 禹州市| 天柱县| 兰西县| 大方县| 万全县| 山东省| 墨竹工卡县| 崇信县| 曲阜市| 海兴县| 东莞市|