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

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.

主站蜘蛛池模板: 常宁市| 定结县| 大渡口区| 辽宁省| 正镶白旗| 榆社县| 高淳县| 临江市| 鄂托克旗| 万山特区| 桦甸市| 绍兴县| 洪雅县| 兴城市| 迁安市| 阳原县| 于田县| 嵊州市| 清远市| 马关县| 银川市| 乌海市| 台州市| 鄄城县| 普格县| 邮箱| 江西省| 无棣县| 张家界市| 临夏县| 乌海市| 龙口市| 望谟县| 体育| 庆阳市| 大理市| 额敏县| 普陀区| 叶城县| 宁津县| 滦平县|