What's a fluent interface?

前端 未结 4 1706
无人及你
无人及你 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:43

    One big difference and advantage of the fluent interface is that you don't need an instance variable to change some properties when you want to create an object and use it as an argument:

    without:

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

    with fluent interface:

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

提交回复
热议问题