If you read the English name, you may think of your liability chain. It is defined to make multiple objects have the opportunity to handle
Request, thereby avoiding the coupling relationship between the requested sender and the recipient. Connect these objects into a chain,
The request is delivered along this chain until there is an object to process it. Then you might misunderstand.
In fact, this model is very similar to newsletter. Just like it is a corresponding message function. At least I finished reading this
This is what you think of. It is also very important. You can even construct a handle to determine the message.
Processing function. Of course, we don't have to SELECT ... CASE .... It is inconvenient. And
It is suitable for object-oriented principles. In fact, this is very flexible to think of a lot of code schemes. Single must consider
1. To expand .2. Easy to call. Below is a set of solutions I offer
Suppose. A parent has a message to "eat" "sleep" "Read", eat must be
Restaurant. Sleeping in the bedroom. Reading in the book tube
// Construct message handle
Public interface ihandler {// string handlername {get;} void request ();
// Event Public Class DiningHandler: ihandler {public void request () {console.writeline ("eat");}}
Public class resthandler: ihandler {public void request () {console.writeline ("Sleeping");}}
Public class readhandler: ihandler {public void request () {console.writeline ("reading");}}
// Event Manager Public Class ManagerHandler {Public iHandler Source; // Event Source Public ManagerHandler (iHandler S) {this.Source = S;}
Public void execute (IREQUEST Request) {request.execute (this.source); // has actual processor to execute}}
// Processor Public Interface IREQUEST {void Execute (iHandler Source);
Public class myrequest: IRequest {public void execute (ihandler Source) {source.Request ();}}
// Customer call public class client {public static int main (string [] args) {ihandler dining = new dininghanlder (); ihandler rest = new restager (); ihandler read = new readageler ();
MangerHandler MH = New MangerHandler (REST); IREQUEST MR = New MyRequest (); MH.EXECUTE (MR);
MH.Source = Dining; MH.EXECUTE (MR); Return 0;}}}