File size: 26,827 Bytes
2e5dac7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | 1
00:00:06,000 --> 00:00:06,000
Hello, Jim.
2
00:00:06,000 --> 00:00:10,000
Today, we are going to lunch with you and other collections of Iraq.
3
00:00:10,000 --> 00:00:15,000
Today we'll talk about you interface and one more important interface that extends you, that is that
4
00:00:15,000 --> 00:00:19,000
interface with the masses in interface.
5
00:00:19,000 --> 00:00:24,000
And I hope you didn't skip lessons because in previous lessons during the General Overy, we already
6
00:00:24,000 --> 00:00:28,000
talked about you and discussed Masset that this interface has.
7
00:00:29,000 --> 00:00:31,000
But today we'll dive into the details.
8
00:00:31,000 --> 00:00:34,000
After that, we'll learn methods in that interface.
9
00:00:34,000 --> 00:00:38,000
Today, we're going to learn what is the difference between these two interfaces.
10
00:00:39,000 --> 00:00:44,000
Also, we'll learn what FTF old principle is and what LIFO principle is.
11
00:00:45,000 --> 00:00:51,000
After we learn interfaces, we'll take a look at the most popular Q and deck implementations.
12
00:00:51,000 --> 00:00:54,000
And I will share with you practical tips and practical cases.
13
00:00:55,000 --> 00:01:00,000
And at the end of the lesson, we are going to review your home task and I will explain how you can
14
00:01:00,000 --> 00:01:01,000
practice your skills.
15
00:01:01,000 --> 00:01:07,000
Let's start and to understand what CU is, we have to understand what FTF old principle is.
16
00:01:08,000 --> 00:01:16,000
If you don't skip lessons, then you remember that FCF also is a method of organizing of a data structure
17
00:01:16,000 --> 00:01:22,000
where the first elements that enter the queue, the first leifs is a Q, in other words, the head of
18
00:01:22,000 --> 00:01:30,000
the queue always processed first f i f o stands for first in first out here on the slide you may see
19
00:01:30,000 --> 00:01:34,000
brutalisation of the Q the Q has the head and the tail.
20
00:01:35,000 --> 00:01:41,000
Students usually wondered where the heart of the Q is and where style of the Q by convention.
21
00:01:41,000 --> 00:01:49,000
The end of the queue at which elements are added is called the tail back Oriya of the Q The end at which
22
00:01:49,000 --> 00:01:53,000
elements are removed is called the hat or front of the Q.
23
00:01:53,000 --> 00:01:58,000
Analogously two words used when people line up to wait for goods or services.
24
00:01:58,000 --> 00:02:00,000
Does it make sense now?
25
00:02:00,000 --> 00:02:03,000
If yes, then let's answer our next question.
26
00:02:03,000 --> 00:02:05,000
Where Q is used.
27
00:02:05,000 --> 00:02:07,000
Imagine that you have two services.
28
00:02:07,000 --> 00:02:11,000
The first service is in charge of onboarding of new customer.
29
00:02:11,000 --> 00:02:18,000
This service process information about the user verifies his payment method at him to the theorem,
30
00:02:18,000 --> 00:02:24,000
checks whether this user already registered, etc. Let's call it onboarding service.
31
00:02:24,000 --> 00:02:30,000
And another service is in charge of handling all payments from the user for his subscription on a monthly
32
00:02:30,000 --> 00:02:30,000
basis.
33
00:02:31,000 --> 00:02:33,000
Let's call this payment service.
34
00:02:33,000 --> 00:02:39,000
Those are two independent services because the first one is in charge of selling subscriptions to customer
35
00:02:39,000 --> 00:02:41,000
only on one side.
36
00:02:41,000 --> 00:02:47,000
But they are different of the similar marketing sites that promotes different products and services
37
00:02:47,000 --> 00:02:47,000
of the company.
38
00:02:48,000 --> 00:02:54,000
Our onboarding service is one out of many services, but the service that is responsible for charging
39
00:02:54,000 --> 00:03:00,000
clients on a monthly basis is used by all websites and systems within the same company.
40
00:03:01,000 --> 00:03:06,000
This is real life scenarios that my team implemented in simplified form also.
41
00:03:06,000 --> 00:03:08,000
But still, I believe you got my point.
42
00:03:08,000 --> 00:03:14,000
And before process payment information from any of the website, the queue exists.
43
00:03:14,000 --> 00:03:21,000
It exists right in the middle between all services and charge and service and all services, including
44
00:03:21,000 --> 00:03:25,000
our onboarding service submits the message in the queue.
45
00:03:25,000 --> 00:03:33,000
The message contains payment profile of our customer and product details and our payment service process.
46
00:03:33,000 --> 00:03:39,000
All these messages one by one and implements all necessary logic related for recurring payments.
47
00:03:40,000 --> 00:03:41,000
Does it make more sense now?
48
00:03:42,000 --> 00:03:43,000
Can you understand now?
49
00:03:43,000 --> 00:03:45,000
Why do we need Kyuss hope?
50
00:03:45,000 --> 00:03:49,000
This brings more clarity and you understand why we need to use Qs.
51
00:03:50,000 --> 00:03:57,000
OK, if you understood cuz let's understand what a deck is and to understand that we have to understand
52
00:03:57,000 --> 00:03:59,000
what LIFO principle is.
53
00:04:00,000 --> 00:04:06,000
LIFO is a method of organizing the manipulation of a data, whereas the last element that entered the
54
00:04:06,000 --> 00:04:09,000
container should be processed first.
55
00:04:09,000 --> 00:04:12,000
LIFO stands for Last In, First Out.
56
00:04:13,000 --> 00:04:19,000
If you remember stack class that extends vector, that is also implementation of LIFO principle.
57
00:04:20,000 --> 00:04:23,000
And on the screen you can see visualisation of stack.
58
00:04:23,000 --> 00:04:30,000
But where we might want to apply LIFO principle, the easiest example of that usage, which you are
59
00:04:30,000 --> 00:04:32,000
faced with on a daily basis, is in the clips.
60
00:04:33,000 --> 00:04:36,000
Have you ever used and do operations in Eclipse?
61
00:04:36,000 --> 00:04:38,000
How do you think the operation works?
62
00:04:39,000 --> 00:04:45,000
Each batch of changes is put in the stack and then the case and those short cards is correct.
63
00:04:45,000 --> 00:04:48,000
The latest separation is removed from the stack.
64
00:04:48,000 --> 00:04:51,000
For example, you wrote Hello World.
65
00:04:51,000 --> 00:04:54,000
The World World is on top of your stack.
66
00:04:54,000 --> 00:04:58,000
When you want to run the operation, it leaves the stack first.
67
00:04:58,000 --> 00:05:00,000
Or imagine your browser history.
68
00:05:00,000 --> 00:05:02,000
You open new pages and then you need.
69
00:05:03,000 --> 00:05:10,000
The return on the previous page or asset allocation in your Java program, we can call one message from
70
00:05:10,000 --> 00:05:16,000
another one and after that call one more method how to track the flow of program execution only with
71
00:05:16,000 --> 00:05:23,000
the help of the stack data structure that stores elements according to LIFO method that it makes more
72
00:05:23,000 --> 00:05:23,000
sense.
73
00:05:23,000 --> 00:05:26,000
Now, can you understand now when do we need stack?
74
00:05:27,000 --> 00:05:27,000
Awesome.
75
00:05:28,000 --> 00:05:34,000
And now when you understood what CU and DEC is and why we need them, I suggest dive deeper into the
76
00:05:34,000 --> 00:05:36,000
details and learn interfaces.
77
00:05:36,000 --> 00:05:40,000
Here is a new interface we have at and of a message here.
78
00:05:41,000 --> 00:05:43,000
Both exist to add elements to the queue.
79
00:05:44,000 --> 00:05:47,000
Both returns through in case element was added to the queue.
80
00:05:48,000 --> 00:05:52,000
Then why do we need two similar methods and why do we need add method here?
81
00:05:52,000 --> 00:05:54,000
If it is present in collection interface?
82
00:05:55,000 --> 00:06:01,000
Let's understand the difference at that is present in queue interface to highlight the specific behavior
83
00:06:01,000 --> 00:06:06,000
of that method in queue type add method adds elements to the queue.
84
00:06:06,000 --> 00:06:12,000
But as you can see from the documentation here in legal state, exceptions will be thrown in case element
85
00:06:12,000 --> 00:06:15,000
couldn't be added because of the capacity restrictions.
86
00:06:16,000 --> 00:06:21,000
To be honest, in most of the cases you wouldn't see this error while working with the implementation
87
00:06:21,000 --> 00:06:23,000
of the queue interface.
88
00:06:23,000 --> 00:06:23,000
Why?
89
00:06:24,000 --> 00:06:29,000
Because most of the implementations have no restrictions on capacity and their unbounded.
90
00:06:30,000 --> 00:06:34,000
And in this case there is no difference between at and of.
91
00:06:34,000 --> 00:06:41,000
A method of a method doesn't throw exception in case element is not added because of the capacity restrictions.
92
00:06:41,000 --> 00:06:44,000
It also can return false hope.
93
00:06:44,000 --> 00:06:49,000
This knowledge will help you during the interview, in case you will be asked what the difference is
94
00:06:49,000 --> 00:06:52,000
between add and offer method in queue interface.
95
00:06:52,000 --> 00:06:53,000
Let's move on.
96
00:06:53,000 --> 00:06:58,000
We have two methods to retrieve elements from the heart of the queue and remove it from the queue.
97
00:06:59,000 --> 00:07:01,000
Zaya, remove and pull.
98
00:07:01,000 --> 00:07:06,000
The only difference between them is the way how they behave in case there are no more elements in the
99
00:07:06,000 --> 00:07:07,000
queue.
100
00:07:07,000 --> 00:07:13,000
Remove Masset in this case will throw no such element exception and Paul MassArt will just returns.
101
00:07:13,000 --> 00:07:16,000
And now what do you see in real life?
102
00:07:16,000 --> 00:07:19,000
I would say evaluate the logic of execution of your program.
103
00:07:19,000 --> 00:07:26,000
First, in case you would ask me what method I would use, I would use full method and would just perform
104
00:07:26,000 --> 00:07:26,000
null check.
105
00:07:27,000 --> 00:07:31,000
I just afraid of all exceptions and I would rather opt for options.
106
00:07:31,000 --> 00:07:37,000
That doesn't throw an exception, but all cases and programming styles are different and I can accept
107
00:07:37,000 --> 00:07:38,000
that.
108
00:07:38,000 --> 00:07:40,000
And that's why it's up to you.
109
00:07:40,000 --> 00:07:44,000
Which method to choose is a similar situation with the next two methods.
110
00:07:45,000 --> 00:07:50,000
We have two methods that allows us to get the elements from the head of the queue, but that don't remove
111
00:07:50,000 --> 00:07:54,000
element from the queue zaya element and pick.
112
00:07:55,000 --> 00:07:58,000
The only difference is that element Masad Maestro.
113
00:07:58,000 --> 00:08:03,000
No such element exception in case there is no more aliments and big method would just return.
114
00:08:03,000 --> 00:08:06,000
Now you already know what I would choose.
115
00:08:06,000 --> 00:08:09,000
That's all methods that are declared in queue interface.
116
00:08:09,000 --> 00:08:14,000
Let's move further and let's investigate what message do we have in that interface.
117
00:08:14,000 --> 00:08:22,000
So as we already discussed, that extends queue interface and organizes data according to LIFG principle.
118
00:08:23,000 --> 00:08:28,000
Let's review methods now that are present here in the top of our list.
119
00:08:28,000 --> 00:08:34,000
We can find a lot of similar methods that can work with the head and with the tail of the queue at first
120
00:08:34,000 --> 00:08:37,000
and at last of a first and of last.
121
00:08:38,000 --> 00:08:44,000
Remove first and remove last, both first and last week first and pick last.
122
00:08:44,000 --> 00:08:46,000
I believe it is clear how they work.
123
00:08:46,000 --> 00:08:52,000
Since we discussed similar methods in queue interface, I noticed that there is no element first and
124
00:08:52,000 --> 00:08:57,000
element last method if to follow the analogy in is naming.
125
00:08:57,000 --> 00:09:03,000
But do we have methods that doesn't remove element from the queue and throws an exception in case there
126
00:09:03,000 --> 00:09:03,000
is no element?
127
00:09:04,000 --> 00:09:08,000
Yes, we have aget first and last method here.
128
00:09:08,000 --> 00:09:14,000
They here also to interest in masses, remove first Securus and remove last appearance.
129
00:09:14,000 --> 00:09:20,000
When we are referring to the first occurrence, we mean first in case we would reverse elements from
130
00:09:20,000 --> 00:09:21,000
the had the tail.
131
00:09:21,000 --> 00:09:27,000
So the first Securus will be closer to the heart of the queue and the last appearance is closer to the
132
00:09:27,000 --> 00:09:28,000
tail of the queue.
133
00:09:29,000 --> 00:09:36,000
After that abasic message from the queue go here and en masse, it adds all elements to the container,
134
00:09:36,000 --> 00:09:39,000
the same as it is declared in connection interface.
135
00:09:39,000 --> 00:09:45,000
There is only one clarification that all elements will be inserted into the end of the queue.
136
00:09:45,000 --> 00:09:47,000
And here are static methods.
137
00:09:47,000 --> 00:09:53,000
We already discussed what the stack is and here's a mass to manage stack push.
138
00:09:53,000 --> 00:09:55,000
It adds element in the heart of the queue.
139
00:09:55,000 --> 00:09:58,000
This method will throw illegal state exception in the case.
140
00:09:58,000 --> 00:10:02,000
Element can't be added due to capacity restrictions.
141
00:10:02,000 --> 00:10:05,000
This method is similar to at first method.
142
00:10:05,000 --> 00:10:08,000
This is even specified in general documentation.
143
00:10:08,000 --> 00:10:10,000
Then why do we need it at all?
144
00:10:11,000 --> 00:10:16,000
For compatibility reasons with legacy class stack, the push and pop methods exist.
145
00:10:16,000 --> 00:10:21,000
This means that they're only to make a transition of all code easier for programa.
146
00:10:22,000 --> 00:10:26,000
The pop method is here and it is equivalent of remove first MassArt.
147
00:10:27,000 --> 00:10:32,000
And I believe you already understood why Oracle left this method in this interface.
148
00:10:32,000 --> 00:10:36,000
The last message that we didn't talk about is the sending iterator.
149
00:10:37,000 --> 00:10:42,000
This message, according to the interface, should return iterator objects that can iterate over the
150
00:10:42,000 --> 00:10:44,000
elements in reverse sequential order.
151
00:10:45,000 --> 00:10:50,000
That is from the last element from our tail to the first element to our hat.
152
00:10:51,000 --> 00:10:54,000
That's all matters that we have in our back interface.
153
00:10:54,000 --> 00:10:58,000
Now let's investigate the most popular Q and deck implementations.
154
00:10:59,000 --> 00:11:05,000
On this slide, you can see the most popular implementations of Q and back interfaces, I recommend
155
00:11:05,000 --> 00:11:08,000
you post the video and read the slide attentively.
156
00:11:09,000 --> 00:11:13,000
I believe there is no need to investigate each of these class in details.
157
00:11:13,000 --> 00:11:19,000
It is better to put our focus on the most popular implementations, the most popular implementation,
158
00:11:19,000 --> 00:11:26,000
in my opinion, and based on the official Oracle tutorials can be split in two major categories implementations
159
00:11:26,000 --> 00:11:30,000
of the interface and implementations of just rescue interface.
160
00:11:30,000 --> 00:11:36,000
In case you need the implementations, then most likely you will be happy with slinked list or array
161
00:11:36,000 --> 00:11:37,000
that class.
162
00:11:37,000 --> 00:11:43,000
If you need Q implementations, most likely you will opt for lenth list of priority queue if you need
163
00:11:43,000 --> 00:11:45,000
thread safe implementations of the queue.
164
00:11:45,000 --> 00:11:50,000
I would like to draw attention to avoid blocking Q and priority blocking queue.
165
00:11:50,000 --> 00:11:55,000
If you need thread safe implementations of DEC, then your choice is linked lock and DEC.
166
00:11:56,000 --> 00:11:58,000
As you can see there is really a lot of options.
167
00:11:59,000 --> 00:12:06,000
But in my opinion and based on my experience in 95 percent of cases when you would need to use DEC implementation
168
00:12:06,000 --> 00:12:12,000
to implement some stack or in case you would need Q you would use in case class the rest five percent
169
00:12:12,000 --> 00:12:17,000
of cases is for thread safe implementation of the Q and DEC and also priority.
170
00:12:17,000 --> 00:12:25,000
Q taking into account we already had lesson about Lindley's and we already learned the Q and DEC interfaces.
171
00:12:25,000 --> 00:12:29,000
There will be nothing hard for you just to call these methods on linked list.
172
00:12:29,000 --> 00:12:34,000
And that is why, for the sake of the demo, I would like to show you how AQ works on the example of
173
00:12:34,000 --> 00:12:35,000
priority.
174
00:12:35,000 --> 00:12:38,000
Q So here I prepared them file.
175
00:12:38,000 --> 00:12:43,000
I will leave link to this file in attachments to the lesson so that you could copy and run this file
176
00:12:43,000 --> 00:12:44,000
on your local computer.
177
00:12:45,000 --> 00:12:47,000
Here I declare it variable of type.
178
00:12:47,000 --> 00:12:51,000
Q Parametrized with the integer type here I created object of.
179
00:12:52,000 --> 00:12:57,000
Q And in these lines you can see that I added to the Q five elements.
180
00:12:57,000 --> 00:13:00,000
They are two eight three one then.
181
00:13:01,000 --> 00:13:05,000
So in the case I'd like to take the first element in the Q what it would be.
182
00:13:06,000 --> 00:13:10,000
Take your time to think about this question because this is a trick question.
183
00:13:11,000 --> 00:13:17,000
We all know how Q works and what is a five for principle, but priority Q has interesting feature.
184
00:13:18,000 --> 00:13:22,000
It automatically source elements according to the natural order.
185
00:13:22,000 --> 00:13:26,000
I hope you didn't skip the lesson about comparator uncomparable.
186
00:13:26,000 --> 00:13:32,000
And you know that natural order is an order that is described in the compared to method because of implementation
187
00:13:32,000 --> 00:13:33,000
of comparable interface.
188
00:13:34,000 --> 00:13:40,000
And that's where a provocative word comes from in the name of the Q it prioritize elements.
189
00:13:40,000 --> 00:13:46,000
So in case I would prefer to control the elements from the head of the Q this would be one even despite
190
00:13:46,000 --> 00:13:50,000
integer object was well your one wasn't inserted the first.
191
00:13:51,000 --> 00:13:53,000
Let me run the program to show you this.
192
00:13:53,000 --> 00:13:57,000
I used polymathic to get elements from the Q and remove it.
193
00:13:57,000 --> 00:14:04,000
So the size of the Q right now is four now in case I call Big Masset and get the hell out of the Q,
194
00:14:04,000 --> 00:14:07,000
but don't remove element here.
195
00:14:07,000 --> 00:14:11,000
You can see in console output that our next object and our priority.
196
00:14:11,000 --> 00:14:13,000
Q is to and the size of the peak.
197
00:14:14,000 --> 00:14:21,000
It is still four because I didn't remove elements from the Q Pay attention to the fact that all elements
198
00:14:21,000 --> 00:14:22,000
that you put into the priority.
199
00:14:22,000 --> 00:14:28,000
Q should implement comparable interface because in case type doesn't implement comparable interface,
200
00:14:28,000 --> 00:14:35,000
Breuer's UCU object would throw exception, glossiest exception that would say that your type cannot
201
00:14:35,000 --> 00:14:37,000
be cast to comparable type.
202
00:14:37,000 --> 00:14:39,000
Let me show you an example.
203
00:14:39,000 --> 00:14:46,000
Let me comment these lines of code here, you can see that I create Q Parametrized by product type.
204
00:14:46,000 --> 00:14:53,000
Just to remind you, product is our custom type that we created during our work on online store implementation.
205
00:14:53,000 --> 00:14:56,000
After that, I want to place my product into this.
206
00:14:56,000 --> 00:15:04,000
Q Let me run the program to show you what would happen and here you can see glass cast exception.
207
00:15:04,000 --> 00:15:05,000
What to do now?
208
00:15:06,000 --> 00:15:07,000
We have two options here.
209
00:15:08,000 --> 00:15:13,000
The first one is to use only types that implement comparable interface.
210
00:15:13,000 --> 00:15:16,000
The second option is to set our priority.
211
00:15:16,000 --> 00:15:18,000
Q How to compare elements.
212
00:15:18,000 --> 00:15:23,000
Let me comment these lines of code to show you the next example here.
213
00:15:23,000 --> 00:15:29,000
You can see that I created the same Q Parametrized by product type, but I pass the product comparison
214
00:15:29,000 --> 00:15:31,000
to the constructor of prosecute.
215
00:15:32,000 --> 00:15:40,000
Now my project knows how to compare products and saw them let me run the program and we can't see error
216
00:15:40,000 --> 00:15:40,000
anymore.
217
00:15:41,000 --> 00:15:47,000
That is because our Q knows how to prioritize products, where to use priority.
218
00:15:47,000 --> 00:15:51,000
Q Imagine that you want to implement helpdesk during the day.
219
00:15:51,000 --> 00:15:57,000
You receive tons of requests and complaints, but you have limited number of operators in your company
220
00:15:57,000 --> 00:15:58,000
that can.
221
00:15:58,000 --> 00:16:05,000
These requests and you have special app for your operators where each operator can click a button,
222
00:16:05,000 --> 00:16:12,000
they can request and move it in progress, and it is obvious that most critical requests should be processed
223
00:16:12,000 --> 00:16:18,000
first in case a customer can't make a payment in the online store or customer already paid.
224
00:16:18,000 --> 00:16:23,000
But some error happened and he or she can't get details of his order.
225
00:16:23,000 --> 00:16:29,000
That is more critical than some random question, like one sorting by manufacturer will be implemented
226
00:16:29,000 --> 00:16:30,000
on your site.
227
00:16:30,000 --> 00:16:37,000
They agree with me and what you have to do probably on the front end, you would implement some dropdown
228
00:16:37,000 --> 00:16:40,000
where you would ask your customer to categorize request.
229
00:16:41,000 --> 00:16:47,000
For example, here on the slide you can see example of support of Panya in your system.
230
00:16:47,000 --> 00:16:50,000
You have some object, something like support ticket type.
231
00:16:50,000 --> 00:16:54,000
You also have to implement logic that would assign support ticket type.
232
00:16:54,000 --> 00:17:00,000
And based on the type of the request, you would assign priority, high, medium or low.
233
00:17:00,000 --> 00:17:04,000
And after that you would pull your support ticket object into the queue.
234
00:17:05,000 --> 00:17:11,000
And you already know that we have to either implement compatible interface in our support ticket or
235
00:17:11,000 --> 00:17:14,000
we have to create a competitor and pass it to priority queue.
236
00:17:14,000 --> 00:17:15,000
Interesting.
237
00:17:15,000 --> 00:17:17,000
I hope it is.
238
00:17:17,000 --> 00:17:23,000
And moreover, implementing something like this already a real life task for our software engineer.
239
00:17:23,000 --> 00:17:25,000
This will be your homework.
240
00:17:25,000 --> 00:17:30,000
But before I would share with you the details of your homework, let's recap what we have learned today.
241
00:17:31,000 --> 00:17:33,000
Today we learned Q and DEC interfaces.
242
00:17:34,000 --> 00:17:38,000
We learned in detail how matters that are described in these interfaces work.
243
00:17:39,000 --> 00:17:43,000
We learned what a FFO and LIFO data store methods are.
244
00:17:44,000 --> 00:17:49,000
We used you and DEC implementations and learned the most popular ones after that.
245
00:17:49,000 --> 00:17:56,000
On the real example, we learned how particular works and now I suggest reviewing your homework.
246
00:17:56,000 --> 00:18:02,000
You have to implement helpdesk facades that would serve as a main interface for a support engineer to
247
00:18:02,000 --> 00:18:09,000
interact with the system, helpdesk facade interface has only three masses that you support.
248
00:18:09,000 --> 00:18:16,000
You could get next support ticket and get a number of tickets according to our requirements, get next
249
00:18:16,000 --> 00:18:16,000
support ticket.
250
00:18:16,000 --> 00:18:20,000
Masset will be called when your support engineer would click on the button.
251
00:18:21,000 --> 00:18:24,000
This message should return top priority item.
252
00:18:24,000 --> 00:18:29,000
I almost explained to you how to implement Help Desk in the online store.
253
00:18:29,000 --> 00:18:35,000
Here you can find the details about what request type might be and priority for specific request type
254
00:18:36,000 --> 00:18:42,000
during the creation of the support ticket will specify only typos request and its priority is defined
255
00:18:42,000 --> 00:18:45,000
automatically based on the Moppin that are written down in the table.
256
00:18:46,000 --> 00:18:48,000
And there is one more requirement in the case.
257
00:18:48,000 --> 00:18:51,000
Support tickets have the same priority.
258
00:18:51,000 --> 00:18:54,000
The one that was created earlier should be processed first.
259
00:18:55,000 --> 00:18:57,000
I can give you a small hint here.
260
00:18:57,000 --> 00:18:58,000
You can implement counter.
261
00:18:59,000 --> 00:19:04,000
This even might be static field and you may consider the value of this field when you would compare
262
00:19:04,000 --> 00:19:06,000
to support tickets, for example.
263
00:19:06,000 --> 00:19:08,000
Does it make sense home?
264
00:19:08,000 --> 00:19:09,000
The task is clear for you.
265
00:19:10,000 --> 00:19:15,000
This is a really interesting task that will help you a lot in understanding of the cues and will give
266
00:19:15,000 --> 00:19:17,000
you some clues to real life experience.
267
00:19:18,000 --> 00:19:19,000
Thank you all for your attention.
268
00:19:19,000 --> 00:19:22,000
Have a great day and see you in the next lesson.
|