Builder Design Pattern in TS
This blog is my knowledge dump. For more structured blogs visit: https://medium.com/@ArcadeBuilds
Creational pattern used for creating objects in TS
We define additional functions which we can method chain to the object
Eg. of use functions are like get, set methods
Full code
class Person {
name: string;
age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
getName = (): string => {
return this.name;
};
setName = (name: string) => {
this.name = name;
};
getAge = (): number => {
return this.age;
};
setAge = (age: number) => {
this.age = age;
};
}
const person1 = new Person("Ben", 14);
console.log(person1);
person1.setAge(24);
console.log(person1);