What is the “Execute Around” idiom?

后端 未结 8 1426
不思量自难忘°
不思量自难忘° 2020-11-22 12:39

What is this \"Execute Around\" idiom (or similar) I\'ve been hearing about? Why might I use it, and why might I not want to use it?

8条回答
  •  我在风中等你
    2020-11-22 13:15

    An Execute Around Method is where you pass arbitrary code to a method, which may perform setup and/or teardown code and execute your code in between.

    Java isn't the language I'd choose to do this in. It's more stylish to pass a closure (or lambda expression) as the argument. Though objects are arguably equivalent to closures.

    It seems to me that the Execute Around Method is sort of like Inversion of Control (Dependency Injection) that you can vary ad hoc, every time you call the method.

    But it could also be interpreted as an example of Control Coupling (telling a method what to do by its argument, literally in this case).

提交回复
热议问题