The free interface is Eric Evans, and it's just another name for the chain of methods. Martin Fowler has written a couple of articles on this subject, but it looks something like this:
m_Window = window::with() .width(l_Width) .height(l_Height) .title("default window") .left(200) .top(200) .create();
A free interface is usually used to create named parameters in a language that does not support them (for example, an idiom of a named parameter in C ++) or in domain languages โโto make the code smoother.
I saw how they were used for everything from image processing libraries, regular expression libraries, three-dimensional libraries. Other examples include building tree structures, lists, or other data structures. Anything that requires building complex objects (loading parameters) can use Fluent Interfaces to make it more readable. For example, compare the previous example with a call to the CreateWindow function:
::CreateWindow( "Window class", "Window title", dwStyle, X, Y, nWidth, nHeight, hWndPant, hMenu, hInstance, NULL );
Jasper Bekkers Jan 11 '09 at 19:24 2009-01-11 19:24
source share