1
00:00:00,740 --> 00:00:01,950
[Autogenerated] we can think about certain

2
00:00:01,950 --> 00:00:04,580
principles that suggest when we might use

3
00:00:04,580 --> 00:00:07,110
an adapter as the solution to certain

4
00:00:07,110 --> 00:00:09,340
kinds of interface incompatibility

5
00:00:09,340 --> 00:00:12,270
problems. We can look to replace

6
00:00:12,270 --> 00:00:14,720
conditional logic with Polymorphism, which

7
00:00:14,720 --> 00:00:17,630
is a specific re factory, by establishing

8
00:00:17,630 --> 00:00:20,010
a common interface for several related

9
00:00:20,010 --> 00:00:22,960
operations. I discussed this for factoring

10
00:00:22,960 --> 00:00:26,400
in detail in my room factoring courses,

11
00:00:26,400 --> 00:00:29,010
for instance, in the code we just saw. The

12
00:00:29,010 --> 00:00:31,540
conditional logic could all be replaced if

13
00:00:31,540 --> 00:00:33,720
we were able to call a method to get

14
00:00:33,720 --> 00:00:37,110
people from a common abstraction. Such

15
00:00:37,110 --> 00:00:39,270
code would also better follow solid

16
00:00:39,270 --> 00:00:42,530
principles. We would also like our code to

17
00:00:42,530 --> 00:00:44,480
be loosely coupled to third party

18
00:00:44,480 --> 00:00:47,260
dependencies like specific files or AP

19
00:00:47,260 --> 00:00:50,260
eyes. That means we should be able to plug

20
00:00:50,260 --> 00:00:52,260
in different service providers without

21
00:00:52,260 --> 00:00:55,500
having to perform surgery on our code.

22
00:00:55,500 --> 00:00:57,590
And, of course, we'd like our code to be

23
00:00:57,590 --> 00:01:00,130
testable. This goes hand in hand with

24
00:01:00,130 --> 00:01:02,260
loose coupling, since tight coupling to

25
00:01:02,260 --> 00:01:04,700
infrastructure concerns makes code very

26
00:01:04,700 --> 00:01:07,660
difficult to unit. Test unit tests need to

27
00:01:07,660 --> 00:01:09,490
be able to run without infrastructure.

28
00:01:09,490 --> 00:01:11,710
Being present in the initial code we're

29
00:01:11,710 --> 00:01:14,070
looking at simply does not work. If

30
00:01:14,070 --> 00:01:16,570
there's not a Jason file or the Star Wars,

31
00:01:16,570 --> 00:01:20,160
a P I present. I've mentioned solid. So

32
00:01:20,160 --> 00:01:21,800
let's consider a few of these principles

33
00:01:21,800 --> 00:01:24,130
as well. If we're to follow the single

34
00:01:24,130 --> 00:01:26,410
responsibility principle, we wanna have

35
00:01:26,410 --> 00:01:30,140
small focus types that only do one thing.

36
00:01:30,140 --> 00:01:32,500
These types should have few public methods

37
00:01:32,500 --> 00:01:34,910
and properties and thus should follow the

38
00:01:34,910 --> 00:01:37,870
interface segregation principle. When you

39
00:01:37,870 --> 00:01:39,920
follow these two principles, it makes it

40
00:01:39,920 --> 00:01:42,190
really easy to create adapters because

41
00:01:42,190 --> 00:01:44,840
they're going to be small and focused. If

42
00:01:44,840 --> 00:01:46,570
you don't follow these two principals,

43
00:01:46,570 --> 00:01:48,310
you're likely to break the list cough

44
00:01:48,310 --> 00:01:50,470
substitution principle because you might

45
00:01:50,470 --> 00:01:52,650
decide not to fully implement Ah, large

46
00:01:52,650 --> 00:01:55,750
interface. We'd also like to be able to

47
00:01:55,750 --> 00:01:58,420
modify our client codes behavior, how it

48
00:01:58,420 --> 00:02:00,240
gets data from its service providers

49
00:02:00,240 --> 00:02:03,100
without having to change its code. This is

50
00:02:03,100 --> 00:02:06,340
an example of the open closed principle.

51
00:02:06,340 --> 00:02:08,690
We want our list characters method to be

52
00:02:08,690 --> 00:02:11,290
open to extension of its behavior in terms

53
00:02:11,290 --> 00:02:13,340
of being able to get data from any number

54
00:02:13,340 --> 00:02:17,210
of sources but close to modification, we

55
00:02:17,210 --> 00:02:21,000
shouldn't need to change its actual source good to achieve this

