A starting idea: suppose we had a DatabaseAction object with instance variables query, success, fail, and message. Suppose when it was created, it sent itself the message execute(). Suppose that object encapsulated everything. The code, in Smalltalk, might look like this:
DatabaseAction query: queryThatCouldFail success: updateThatCouldFail failure: anotherThingThatCouldFail message: tellUserItDidn'tWorkNaturally there would be default forms such as
DatabaseAction query: queryThatCouldFailCould a system built around DatabaseAction be simpler, more clear, faster to write, more reliable than hand-coding conditional OR try/catch code? Nah, probably not.
Hey, pull the execute call out of construction, make it a composite and implement transactions. Why wouldn't it work? -- MichaelFeathers
It would. But don't tell the C++ guys.