English 中文(简体)
什么是流动接口?
原标题:What s a fluent interface?

我最近遇到了这个表达 - 但是阅读了维基百科上的相关内容并没有为我澄清太多 - 我还是不太理解它。

  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)?

最佳回答

它通过减少他必须的类型(和阅读)使编码员受益。

• 在Wikipedia使用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); // Set window params
     app.setWindowPosition(200, 200);
     app.setTitle("My OpenGL/GLUT App");
     app.create();
}

之后:

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

对“脆弱接口”一词有不同的解释。 在C++中建立一个系统的一个共同方法是方法链条,通常用于例如,因特网图书馆:

Object.MethodA().MethodB();
cout << "a = " << a;

The Named Paraile Idiom,是通风的另一 n:

Window w = CreateWindow()
               .Width(400)
               .Height(300)
               .OnTop();

好处? 尽管这仍然取决于课程的实施,但守则更可读和更灵活。

流动界面的一大区别和优势是,在你想要制造物体并将其作为理由时,你不需要改变某些特性的试样:

无:

Object object;
object.setcolor("red"); 
object.setstyle("solid");
object.setname("test");
world.CreateNode(object);

a. 与流体接口:

world.CreateNode(Object()
                                           .setcolor("red")
                                           .setstyle("solid")
                                           .setname("test")
                             );

CallStream aka "Why the dot s ?" :)

没有什么错误(非常简单) Java版,描述新的重要概念。 C++也完全可行。

关键概念:利用职能规划部分来描述接口。 如果不使用:电文论点作为示意图,就等于概念。

我认为,这主要涉及“学校”模式,但还是与“建筑模式”有关。 而且,它似乎还在“Monads”上生存。

btw:上述所有倡导者都提出了非常好的使用案例。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签