1 00:00:00,920 --> 00:00:06,850 Let's take a look first at the handler interface here, the contract for the handlers. 2 00:00:07,040 --> 00:00:10,970 So as you can see, there is only one method here for handling requests. 3 00:00:11,270 --> 00:00:15,140 And by the way, you may recognize this code from the flyaway tutorial. 4 00:00:15,150 --> 00:00:16,730 So it's the same one. 5 00:00:16,730 --> 00:00:21,560 But I have adapted it for including the chain of responsibility pattern. 6 00:00:21,830 --> 00:00:25,700 So the handler interface will be implemented by our handlers. 7 00:00:25,700 --> 00:00:31,160 The authentication one is the first one and the authorization will be the second in the chain. 8 00:00:31,490 --> 00:00:35,450 So this is how the authentication handler looks like. 9 00:00:35,450 --> 00:00:40,070 It has a reference to the next item in the chain, which is the authorization handler. 10 00:00:40,280 --> 00:00:48,380 And for the handler requests does have a simple Sisso statement here, but it also will have a reference 11 00:00:48,380 --> 00:00:54,150 to the handler request submitted from the authorization object, as you can see here. 12 00:00:54,350 --> 00:01:01,340 So basically the check authorization method will have a reference, will call the handler request method 13 00:01:01,520 --> 00:01:07,170 that is being part of the handler interface here from the authorization handler. 14 00:01:07,310 --> 00:01:14,960 So basically here, what we want to attempt is to have an authentication and authorization for a user 15 00:01:14,960 --> 00:01:23,730 of an online shop before he or she may order stuff from from from this online store. 16 00:01:24,380 --> 00:01:30,350 So the code is untouched, the rest of the code, except for the client application, which now needs 17 00:01:30,350 --> 00:01:36,450 to start the process from the authentication part. 18 00:01:36,680 --> 00:01:44,240 So basically, here we have a call for the handler request from the handler, which in our case is the 19 00:01:44,240 --> 00:01:45,410 authentication handler. 20 00:01:45,650 --> 00:01:51,040 Then the request will be passed to the authorization handler, which is the second item in the chain, 21 00:01:51,200 --> 00:01:54,100 and after that, the rest of the code will be executed. 22 00:01:54,410 --> 00:01:56,480 So well, let's start this. 23 00:01:57,780 --> 00:02:04,470 So as you can see, the first message is authentication is successful and the next one is client authorized 24 00:02:04,470 --> 00:02:10,920 to use the system as a customer, which is the message that is printed out by the sender request method 25 00:02:11,220 --> 00:02:13,630 from the authorization handler. 26 00:02:14,580 --> 00:02:17,920 So that's it for the chain of responsibility pattern. 27 00:02:17,940 --> 00:02:21,720 Join me in the next video where we are going to discuss about the command pattern.