opensearch-project / automation-app

🤖 An automation app to handle the daily activities of your GitHub Repository.
Apache License 2.0
1 stars 4 forks source link

[Enhancement] Proper ways of adding getters to classes #5

Closed peterzhuamazon closed 1 month ago

peterzhuamazon commented 2 months ago

These are the getters setup today: https://github.com/opensearch-project/automation-app/blob/9b4854bec987ef7bb674b45932de4cc556104587/src/service/operation/operation.ts#L16-L27

A better way:

export class Operation {
  private _name: string;
  private _events: string[];
  private _tasks: Task[];

  constructor(name: string, events: string[], tasks: Task[]) {
    this._name = name;
    this._events = events;
    this._tasks = tasks;
  }

  public get name(): string {
    return this._name;
  }

  public get events(): string[] {
    return this._events;
  }

  public get tasks(): Task[] {
    return this._tasks;
  }
}

Even better we can just use readonly:

export class Operation {
  readonly name: string;
  readonly events: string[];
  readonly tasks: Task[];

  constructor(name: string, events: string[], tasks: Task[]) {
    this.name = name;
    this.events = events;
    this.tasks = tasks;
  }
}

Thanks.