I understand the importance of encapsulation in OOP, and accessors (getters/setters) provide this level of abstraction.
However, with Typescript I can substitute my property with accessors at a later date, with the same name, and rename my property to be prefixed with an underscore (therefore not causing a breaking change).
For example I could have:
class foo {
name: string;
}
Later if I wish to add accessors to this property I could change to the following:
class foo {
private _name: string;
get name():boolean {
return this._name;
}
set name(name: string) {
this._name = name;
}
}
Is this considered bad practice?
What is the purpose of the accessors in this context?