Business environment background:
Data receiving LayerReceivedDataAndData operation layerTransfer.
Method 1 Event Mode (note that this mode is asynchronous)
Generate an event corresponding to the data at the data receiving layer,
The data operation layer listens for events and processes them accordingly.
Features: Asynchronous mode, low coupling, one-to-multiple
The second method of delegation (note that this method is synchronous)
At the data receiving layer:
Define the data processing delegate at the data receiving layer.
After receiving data, call the defined data processing delegate interface.
Data Processing Layer: In the initial data receiving layer, the data operation is passed to the delegate interface of the Data receiving layer.
Features: Synchronous mode, high coupling, one-to-one
The third method is the observer mode, which defines the processing interface (note that this method is synchronous)
At the data receiving layer:
Define a processing interface at the data receiving Layer
After the data receiving layer obtains the data, it calls the processing class interface directly.
Data Processing Layer:
Define a data processing class that inherits the processing class interface of the Data receiving layer.
When initializing the data receiving layer, pass the data processing class to the data receiving layer.
Can be modified to asynchronous mode
Features: Synchronous mode, with a general Coupling Degree, one-to-one