什么是流畅的界面? [英] What's a fluent interface?

查看:157
本文介绍了什么是流畅的界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了这个表达方式 - 但是阅读了维基百科上的 没有对我有任何解释 - 我还是


  1. 是什么意思

  2. >
    维基百科文章C ++示例过长,并且将流畅界面的讨论与简单的Glut应用程序的示例混合在一起。有人可以提供一个类的SUCCINCT C ++示例来说明一个流畅的接口(例如这样的影响与普通的C ++接口有什么不同)。

    解决方案<



    要使用维基百科上的C ++示例:



    之前:

      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); //设置窗口参数
    app.setWindowPosition(200,200);
    app.setTitle(My OpenGL / GLUT App);
    app.create();
    }

    之后:

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


    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. How is it used in practice (i.e. how does it benefit a coder in their day to day work/building systems)?

    [Edit] The Wikipedia article C++ example is overly long, and conflates the discussion of a fluent interface with an example of a simple Glut app. Can someone provide a SUCCINCT C++ example of a class that illustrates a fluent interface (how does such an influence differ from an ordinary C++ interface for example)?

    解决方案

    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();
     }
    

    这篇关于什么是流畅的界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆