1
00:00:01,940 --> 00:00:02,950
[Autogenerated] Let's look at some code

2
00:00:02,950 --> 00:00:05,520
that demonstrates the need for an adaptor

3
00:00:05,520 --> 00:00:07,740
because it needs to work with several

4
00:00:07,740 --> 00:00:12,090
incompatible interfaces. Our basic client

5
00:00:12,090 --> 00:00:15,140
is a Star Wars character display service

6
00:00:15,140 --> 00:00:17,130
in its current state. It just reads the

7
00:00:17,130 --> 00:00:19,310
characters from a Jason file from the

8
00:00:19,310 --> 00:00:21,820
local disc, formats them a little bit, and

9
00:00:21,820 --> 00:00:24,670
then it displays them. There's a test

10
00:00:24,670 --> 00:00:28,010
runner, and this test runner will call the

11
00:00:28,010 --> 00:00:32,540
service, and then I'll put the result

12
00:00:32,540 --> 00:00:34,640
here. You can see the result from the file

13
00:00:34,640 --> 00:00:38,770
includes these five characters. Now we

14
00:00:38,770 --> 00:00:40,960
want to update the service so that it can

15
00:00:40,960 --> 00:00:43,310
support not just a file, but it can also

16
00:00:43,310 --> 00:00:46,080
call the Star Wars a P I, an online

17
00:00:46,080 --> 00:00:48,120
service that will return back a list of

18
00:00:48,120 --> 00:00:51,620
characters to make this change. We've

19
00:00:51,620 --> 00:00:53,850
modified our method so that it can accept

20
00:00:53,850 --> 00:00:56,490
a character source specifying whether it's

21
00:00:56,490 --> 00:00:58,350
going to be reading from the file as it

22
00:00:58,350 --> 00:01:02,400
did before or from the A P I. You can see

23
00:01:02,400 --> 00:01:04,420
that we have to have some if logic, in

24
00:01:04,420 --> 00:01:06,400
order to change the way that we would

25
00:01:06,400 --> 00:01:08,660
interact with the file based version of

26
00:01:08,660 --> 00:01:11,820
getting this information or with the A P I

27
00:01:11,820 --> 00:01:15,300
based version. Once we have the character

28
00:01:15,300 --> 00:01:17,630
data, the result is the same. We're still

29
00:01:17,630 --> 00:01:20,390
going to just format it and print it out.

30
00:01:20,390 --> 00:01:22,220
And now we can have two different tests

31
00:01:22,220 --> 00:01:24,940
here, though, demonstrate that it works

32
00:01:24,940 --> 00:01:27,570
and you can see if we read from the A P I.

33
00:01:27,570 --> 00:01:28,940
Can we get a slightly different set of

34
00:01:28,940 --> 00:01:33,090
characters. Our problem, though, just to

35
00:01:33,090 --> 00:01:36,360
be clear, is that this is not sustainable

36
00:01:36,360 --> 00:01:39,320
code. If we had another different type of

37
00:01:39,320 --> 00:01:41,330
source, we're gonna have to change this

38
00:01:41,330 --> 00:01:43,110
coat again. And we have a lot of

39
00:01:43,110 --> 00:01:45,620
duplication here in terms of how we're

40
00:01:45,620 --> 00:01:48,210
going in. Fetching the list of people also

41
00:01:48,210 --> 00:01:49,600
were not really following the solid

42
00:01:49,600 --> 00:01:51,180
principles, which you can learn more about

43
00:01:51,180 --> 00:01:53,730
in my courses on plural site on solid.

44
00:01:53,730 --> 00:01:56,400
Specifically, this service is doing way

45
00:01:56,400 --> 00:01:57,810
too much. At this point. It's not

46
00:01:57,810 --> 00:01:59,350
following the single responsibility

47
00:01:59,350 --> 00:02:01,280
principle, and it's also not following the

48
00:02:01,280 --> 00:02:03,830
open closed principle, because any time we

49
00:02:03,830 --> 00:02:06,420
want to change where it's getting its data

50
00:02:06,420 --> 00:02:08,600
from, we have to go in and actually change

51
00:02:08,600 --> 00:02:11,180
this method. Inside this class. It's not

52
00:02:11,180 --> 00:02:13,740
closed for modification when we try and

53
00:02:13,740 --> 00:02:16,380
extend it. So let's think about how we can

54
00:02:16,380 --> 00:02:20,000
approach solving this problem and some principles that might apply

