Created
June 30, 2024 12:07
-
-
Save trikitrok/f87c28748f6b3787a66578e423b63cc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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