DEV Community

Discussion on: When Builder is anti-pattern

Collapse
 
jmkelm08 profile image
jmkelm08

I believe what you are describing is commonly referred to as a fluent interface.

Thread Thread
 
siy profile image
Sergiy Yevtushenko

Fluent interface is orthogonal to the pattern described above.

Thread Thread
 
jmkelm08 profile image
jmkelm08

I don't see how? A fluent interface attempts to guide you through a process without you really having to read the documentation (you feel like you are already fluent in the API). For example, I could have a class like ClientFactory with a single method createClient(). The return from that method could be an object with two methods forAmazon() or forGoogle(). Depending on which method you call you may have different options for how to have the client authenticate. The fluent API gives you limited valid options until you hit a terminal method that finally builds and returns the object you are looking for. It sounds exactly like what you were describing in your DSL like solution above.

Thread Thread
 
siy profile image
Sergiy Yevtushenko

Out of curiosity I've checked what Wikipedia says about fluent interface:

Note that a "fluent interface" means more than just method cascading via chaining; it entails designing an interface that reads like a DSL, using other techniques like "nested functions and object scoping".

So, seems I was wrong about orthogonality. From the other hand, looks like fluent interface is designed to be "DSL-like", so basically it's just two different names for same thing.