Principle
IOU thought is one of the effective ways to deal with the daily debt relationship, namely:
The debtor issues IOU debt vouchers to creditors through a reliable third party custody account;
The debtor terminates the IOU debt by submitting the results to a third party custody account;
The creditor carries out the creditor's right through the third party custody account with this IOU debt certificate and proceeds to redeem.
The debt relationship between debtors and creditors enables maximum separation and decoupling of time and space through reliable third party custody accounts.
IOU design mode is the application of IOU thought in the field of software design, first proposed by Allan Vermeulen in 1996. In the field of software design, the debt relationship occurs between the method caller and the method body, and the debt object is the return result of the method. The normal method's invocation model is that the method body executes synchronously and then returns the result, and the caller must wait for the result to return before executing. In IOU design mode, the method body returns an IOU object immediately, and the promised IOU object will eventually be terminated, and the caller can redeem the result after the IOU object is terminated. During this time, the caller can continue to perform other worthwhile transactions without waiting, thus achieving the goal of increasing the concurrency and asynchrony of the program as a whole.
The IOU design pattern is completely independent of any asynchronous mechanism, and the provider of the IOU object can choose any effective way to perform the service and eventually terminate the IOU object, such as enabling independent thread/Process execution, driving asynchronous event generation, using remote method calls, or waiting for user terminal input, and so on. This is an important factor in the general applicability of the IOU model.
Analysis and implementation of IOU model
The IOU mode is mainly IOU (debt voucher) and escrow (third party custodian account) two objects, the actual use of the pattern will also involve Caller (caller), callee (callee) and Asyncservice (asynchronous services) and other objects.
Sequence diagram
Through sequential graphs, the reader can establish a preliminary impression of the use of the IOU pattern.
Figure 1. IOU Pattern sequence Diagram