When creating a domain model, is it best to define and set the properties inside the constructor for efficiency?
In my attempt below, I have defined the properties outside the constructor. Should I be setting them only inside the constructor to reduce the amount of code?
Here is what I believe to be the correct way:
export class TestModel1 {
public currentPage: number = 0;
public hasNext: boolean = false;
public hasPrev: boolean = false;
public pageSize: number = 0;
public totalItems: number = 0;
constructor(data: any) {
this.currentPage = data.currentPage;
this.hasNext = data.hasNext;
this.hasPrev = data.hasPrev;
this.pageSize = data.pageSize;
this.totalItems = data.totalItems;
}
}
Although functional, this implementation appears lengthy with a lot of lines of code.
Currently, I pass in a data object and then map the values. Is there a more efficient way to achieve this using the constructor function?