Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created June 30, 2024 12:07
Show Gist options
  • Save trikitrok/f87c28748f6b3787a66578e423b63cc8 to your computer and use it in GitHub Desktop.
Save trikitrok/f87c28748f6b3787a66578e423b63cc8 to your computer and use it in GitHub Desktop.
class ClientBuilder {
private age: number;
private height: number;
private constructor() {
}
public static someClient(): ClientBuilder {
return new ClientBuilder();
}
public withAge(age: number): ClientBuilder {
this.age = age;
return this;
}
public withHeight(height: number): ClientBuilder {
this.height = height;
return this;
}
public build(): Client {
return new Client(this.age, this.height);
}
}
// In some client
class SomeBuilderClient {
public someMethod(): void {
ClientBuilder.someClient().withAge(5).withHeight(50).build();
// a.b().c().d()
// Is this a Message Chain smell?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment