接口名称: IUser

接口描述: IUser 接口用于定义用户对象的基本属性和方法。

属性:

  • id: 用户ID,类型为整数。
  • name: 用户名,类型为字符串。
  • email: 用户邮箱,类型为字符串。

方法:

  • getId(): 获取用户ID。
  • getName(): 获取用户名。
  • getEmail(): 获取用户邮箱。
  • setId(id: number): 设置用户ID。
  • setName(name: string): 设置用户名。
  • setEmail(email: string): 设置用户邮箱。

示例代码:

interface IUser {
  id: number;
  name: string;
  email: string;
  getId(): number;
  getName(): string;
  getEmail(): string;
  setId(id: number): void;
  setName(name: string): void;
  setEmail(email: string): void;
}

class User implements IUser {
  id: number;
  name: string;
  email: string;

  constructor(id: number, name: string, email: string) {
    this.id = id;
    this.name = name;
    this.email = email;
  }

  getId(): number {
    return this.id;
  }

  getName(): string {
    return this.name;
  }

  getEmail(): string {
    return this.email;
  }

  setId(id: number): void {
    this.id = id;
  }

  setName(name: string): void {
    this.name = name;
  }

  setEmail(email: string): void {
    this.email = email;
  }
}
写一个接口

原文地址: https://www.cveoy.top/t/topic/gSj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录