-
Notifications
You must be signed in to change notification settings - Fork 238
Open
Description
Hi,
implementation of builder pattern in TS looks like -
export class Student {
name: String;
age: Number;
constructor(studentBuilder: StudentBuilder) {
this.name = studentBuilder.name;
this.age = studentBuilder.age;
}
}
export class StudentBuilder {
private _name: String = "";
private _age: Number = 0;
constructor(){
}
setName(name: String) {
this._name = name
return this
}
setAge(age: Number) {
this._age = age
return this
}
get name(): String {
return this._name
}
get age(): Number {
return this._age
}
build() {
return new Student(this);
}
}
==================================================
client code:
const student = new StudentBuilder().setName("vijay").setAge(29).build()
======================================================
but in java it is some what different.
or there is better way to implementing it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels