Execute Around Pattern

See ResourceAcquisitionIsInitialization for C++, & the Java languages, and BlockClosures for the dynamic languages.

it works like this:

the calling code only wants to think about its context, not what the other half of the whole procedure is up to:

   raw_signal = database.knowledge()

with Plotter('candy.svg') as axes: axes[0].addSignal(raw_signal) iso_signal = calibrator.process(raw_signal) axes[1].addSignal(iso_signal)

# An invisible line of code here actually dresses up and saves the file

Behind the scenes (and switching the language to non-idiomatic Ruby only because the syntax is fall-off-a-log easy), the plotter plots:

   def Plotter(fileName)
       plot = OTC.PlotterSystem?(fileName)
       axis = plot.addAxis()
       yield(axis)  #  We don't care what you do, you don't care what we do
       _addGridCalloutsEtcAndSave(plot)  #  This is the invisible line that's now DRY
   end

That situation isolates two different concerns - calibrating the data and operating the plotter mechanics and glitz. Without it, we would pepper all the plot-data code with redundant plot details. Even worse (and language dependant), the wrapper can elect to not call, repeat, defer, or asynchronize the payload. And, naturally, both systems can upgrade freely, cleanly decoupled from each other.

~~PhlIp


EditText of this page (last edited July 9, 2014) or FindPage with title or text search