Benefits and drawbacks of method chaining and a possibility to replace all void return parameters by the object itself

前端 未结 9 1798
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 06:58

I am mostly interested in Java, but I think it\'s a general question. Recently I\'ve been working with Arquillian framework (ShrinkWrap) that uses a lot of meth

9条回答
  •  眼角桃花
    2020-11-29 07:08

    You may like to read about Fluent Interface by Martin Fowler

    Summarily

    • do not chain method for the heck of it primarily because it breaks the Command Query Responsibility Segregation (CQRS) design principle.
    • improve the api design by bringing it closer to the way business talks about those operations, think about them as internal DSLs
    • try avoiding chaining independent methods because they pollute the API and may not be able to reveal intent to the client/maintainer of the code

提交回复
热议问题