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

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.

主站蜘蛛池模板: 松滋市| 常熟市| 曲松县| 江源县| 亳州市| 介休市| 仲巴县| 醴陵市| 封丘县| 东丰县| 南木林县| 黄大仙区| 修文县| 荥阳市| 吐鲁番市| 湖口县| 宁武县| 永靖县| 苍南县| 贵定县| 巴彦淖尔市| 镇原县| 河南省| 沿河| 巢湖市| 华容县| 灵川县| 杭锦后旗| 凤庆县| 平罗县| 清河县| 平陆县| 南木林县| 华亭县| 哈巴河县| 铁力市| 静海县| 伊金霍洛旗| 胶州市| 巴南区| 许昌市|