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
Print
Share
Comment
Cite
Upload
Translate

APA
decker | Sciencx (2023-10-03T21:15:44+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/.
MLA" » When OOP Developers created Applications with TypeScript." decker | Sciencx - Friday March 25, 2022, https://www.scien.cx/2022/03/25/when-oop-developers-created-applications-with-typescript/
HARVARDdecker | Sciencx Friday March 25, 2022 » When OOP Developers created Applications with TypeScript., viewed 2023-10-03T21:15:44+00:00,<https://www.scien.cx/2022/03/25/when-oop-developers-created-applications-with-typescript/>
VANCOUVERdecker | Sciencx - » When OOP Developers created Applications with TypeScript. [Internet]. [Accessed 2023-10-03T21:15:44+00:00]. Available from: https://www.scien.cx/2022/03/25/when-oop-developers-created-applications-with-typescript/
CHICAGO" » When OOP Developers created Applications with TypeScript." decker | Sciencx - Accessed 2023-10-03T21:15:44+00:00. https://www.scien.cx/2022/03/25/when-oop-developers-created-applications-with-typescript/
IEEE" » When OOP Developers created Applications with TypeScript." decker | Sciencx [Online]. Available: https://www.scien.cx/2022/03/25/when-oop-developers-created-applications-with-typescript/. [Accessed: 2023-10-03T21:15:44+00:00]
rf:citation » When OOP Developers created Applications with TypeScript | decker | Sciencx | https://www.scien.cx/2022/03/25/when-oop-developers-created-applications-with-typescript/ | 2023-10-03T21:15:44+00:00
https://github.com/addpipe/simple-recorderjs-demo