In java, can one create a fluent extensible class hierarchy with methods that can be invoked in any order?

后端 未结 4 1567
忘了有多久
忘了有多久 2021-02-06 17:07

Can one create an extensible class hierarchy in java whose methods are fluent and can be invoked in any order? (YES! see answer below), even for existing classes wh

4条回答
  •  礼貌的吻别
    2021-02-06 17:38

    A fluent interface is a different concern from the normal set of command-query methods that you already have. Separation of concerns makes it a good idea to separate them.

    Since you have an existing hierarchy of code: Write a fluent facade that does the dirty work for you.

    See also Martin Fowler: Domain-Specific Languages, 4.2: The need for a Parsing Layer.

提交回复
热议问题