使用界面创建class模型有感觉吗?

Is there sense of using interface to create class model?

接口为:

export interface IAddEditGeneralDictionary {
      Code: string;
      StartDate?: Date | string;
      FinishDate?: Date | string;
      Name: string;
    }

实现是:

export class AddEditGeneralDictionary implements IAddEditGeneralDictionary {
  constructor(public Code: string,
    public StartDate: Date | string,
    public FinishDate: Date | string,
    public Name: string){
}

我尝试将属性设为私有并使用 set/get,但界面不允许我这样做。

使用接口构建模型有意义吗class?

接口是不同components/entity进行通信的共享边界。它应该是 public 以便用户在从界面调用具体 class 时知道他们期望什么。

无论是私有的 属性 还是方法,它们都是实现细节。具体的就做吧class.

例如

interface Vehicle {
  start(): void;
}

class Car implements Vehicle {
  private engine;
  private wheels;
  public start(): void {}
}

class Jet implements Vehicle {
  private engine;
  private airframe;
  public start(): void {}
}

实现可以自由定义私有属性,但私有属性在接口中不是很有用。