1 00:00:00,790 --> 00:00:07,120 The adaptor pattern is the first design pattern from the structural patterns that we're going to discuss 2 00:00:07,120 --> 00:00:09,140 about generally. 3 00:00:09,400 --> 00:00:14,590 This pattern is used when there is a need to combine the capabilities of the interfaces. 4 00:00:15,700 --> 00:00:21,490 You can think of this pattern as a plug adaptor linking two components that are not compatible with 5 00:00:21,490 --> 00:00:27,970 each other, just like a power socket that does not accept a certain plug and needs an adapter to address 6 00:00:27,970 --> 00:00:28,240 that. 7 00:00:29,770 --> 00:00:36,130 You can use this pattern whenever you are in one of the following situations, you have a legacy application 8 00:00:36,130 --> 00:00:43,030 or interface and you wish to make it work with a newer application, you can use the adapter pattern 9 00:00:43,030 --> 00:00:47,130 to connect the two together without having to change the legacy component. 10 00:00:48,540 --> 00:00:52,920 Another use case is when you need to convert an interface into another. 11 00:00:54,080 --> 00:00:57,860 This is a way to adapt to incompatible interfaces together. 12 00:00:59,470 --> 00:01:04,870 Also, an important use case is when you want to adopt some requests of a client application to a new 13 00:01:04,870 --> 00:01:10,900 Web service and adoptive parent can provide a link to ensure compatibility between the two. 14 00:01:12,700 --> 00:01:16,370 The adoptive father is being used thoroughly in the Java API as well. 15 00:01:17,080 --> 00:01:21,940 Some examples are the collections framework where you can change a collection to another. 16 00:01:23,210 --> 00:01:28,100 One example is changing a race to lists using the athlete's method. 17 00:01:29,040 --> 00:01:34,590 Also, the extremes have plenty of adaptors to make those dreams work with other types of streams or 18 00:01:34,590 --> 00:01:35,220 readers. 19 00:01:37,650 --> 00:01:40,350 Here is a design diagram of a Dr. Peter. 20 00:01:41,210 --> 00:01:47,810 In our example, we will be using a legacy banking application, which needs to send information structure 21 00:01:47,810 --> 00:01:49,210 in a very specific way. 22 00:01:51,060 --> 00:01:57,540 The information will be sent to a news service which, based on the information, will create a banking 23 00:01:57,540 --> 00:01:58,020 account. 24 00:01:59,110 --> 00:02:05,020 We will be using an interface for creating the account and getting the information needed for that account 25 00:02:05,290 --> 00:02:10,120 and then the doctor class that will implement that interface, which will structure the information 26 00:02:10,120 --> 00:02:17,230 based on the contract with the service, the requests will go from the adapter to the service and eventually 27 00:02:17,230 --> 00:02:18,460 the account will be created. 28 00:02:19,450 --> 00:02:21,400 Let's see how this looks in code.