What's a fluent interface?

前端 未结 4 1713
无人及你
无人及你 2020-12-15 07:29

I recently came across this expression - but reading up on Wikipedia did not clarify it much for me - I still don\'t get it:

  1. What\'s the point of it
  2. H
4条回答
  •  星月不相逢
    2020-12-15 07:38

    It benefits the coder by reducing the amount he has to type (and read).

    To use the C++ example on Wikipedia:

    Before:

    int main(int argc, char **argv) {
         GlutApp app(argc, argv);
         app.setDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_ALPHA|GLUT_DEPTH); // Set framebuffer params
         app.setWindowSize(500, 500); // Set window params
         app.setWindowPosition(200, 200);
         app.setTitle("My OpenGL/GLUT App");
         app.create();
    }
    

    After:

     int main(int argc, char **argv) {
         FluentGlutApp app(argc, argv)
             .withDoubleBuffer().withRGBA().withAlpha().withDepth()
             .at(200, 200).across(500, 500)
             .named("My OpenGL/GLUT App");
         app.create();
     }
    

提交回复
热议问题