This content originally appeared on DEV Community and was authored by decker
I recently saw this code for almost 100 Entities.
export interface IXXX {
attr1: string
attr2: string
attr3: string
attr4: string
}
export class XXX implements IXXX {
private _attr1: string = ''
private _attr2: string = ''
private _attr3: string = ''
private _attr4: string = ''
get attr1 (): string {
return this._attr1
}
set attr1 (newattr1: string) {
this._attr1 = newattr1
}
get attr2 (): string {
return this._attr2
}
set attr2 (newattr2: string) {
this._attr2 = newattr2
}
get attr3 (): string {
return this._attr3
}
set attr3 (newattr3: string) {
this._attr3 = newattr3
}
get attr4 (): string {
return this._attr4
}
set attr4 (newattr4: string) {
this._attr4 = newattr4
}
toString (): string {
return this._attr2
}
static createWithData (attr1: string, attr2: string, attr3: string, attr4: string): XXX {
const result = new XXX()
result.attr1 = attr1
result.attr2 = attr2
result.attr3 = attr3
result.attr4 = attr4
return result
}
static createFromObject (someObject: IXXX): XXX {
const newObject = new XXX()
newObject.attr1 = someObject.attr1
newObject.attr2 = someObject.attr2
newObject.attr3 = someObject.attr3
newObject.attr4 = someObject.attr4
return newObject
}
}
What do you think, is this the way to go?
And console.log
seems to get no benefit from this - see toString.
This content originally appeared on DEV Community and was authored by decker
decker | Sciencx (2022-03-25T17:39:07+00:00) When OOP Developers created Applications with TypeScript. Retrieved from https://www.scien.cx/2022/03/25/when-oop-developers-created-applications-with-typescript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.