1
00:00:00,280 --> 00:00:01,600
[Autogenerated] they're actually a couple

2
00:00:01,600 --> 00:00:04,340
of kinds of adapters. Let's talk about

3
00:00:04,340 --> 00:00:06,140
them before we see how to apply them to

4
00:00:06,140 --> 00:00:10,600
the code we've been reviewing. The two

5
00:00:10,600 --> 00:00:13,460
kinds of adapter patterns are object

6
00:00:13,460 --> 00:00:16,560
adapters and class and afters. The big

7
00:00:16,560 --> 00:00:18,310
difference between them is how they

8
00:00:18,310 --> 00:00:20,350
reference the class that they're rapping

9
00:00:20,350 --> 00:00:24,050
or adapting. Object adapters, holding

10
00:00:24,050 --> 00:00:27,470
instance of the adoptee class vacant.

11
00:00:27,470 --> 00:00:30,190
Implement an adapter interface or inherit

12
00:00:30,190 --> 00:00:33,580
from the adapter. Type in the use

13
00:00:33,580 --> 00:00:36,340
composition and single inheritance

14
00:00:36,340 --> 00:00:39,000
languages like C Sharp and Java on Lee

15
00:00:39,000 --> 00:00:41,010
support single inheritance, meaning you

16
00:00:41,010 --> 00:00:43,100
can't define a class that inherits from

17
00:00:43,100 --> 00:00:47,560
more than one other class class adapters

18
00:00:47,560 --> 00:00:50,470
inherit from the adoptees and the adapter

19
00:00:50,470 --> 00:00:53,790
type. Thus they require multiple

20
00:00:53,790 --> 00:00:58,580
inheritance. One variation of classic

21
00:00:58,580 --> 00:01:00,750
after that doesn't require multiple class

22
00:01:00,750 --> 00:01:03,590
inheritance. Simply implements the adapter

23
00:01:03,590 --> 00:01:07,100
interface. This variation can be used in

24
00:01:07,100 --> 00:01:12,320
languages like C Sharp and Java. In C

25
00:01:12,320 --> 00:01:15,380
sharp, you'll mostly use object adapters.

26
00:01:15,380 --> 00:01:17,690
The reason is that C Sharp doesn't support

27
00:01:17,690 --> 00:01:19,730
multiple inheritance. In a design

28
00:01:19,730 --> 00:01:22,100
principle of C. Sharp is to prefer

29
00:01:22,100 --> 00:01:24,950
composition over inheritance. In the

30
00:01:24,950 --> 00:01:27,520
diagram shown here, the client is able to

31
00:01:27,520 --> 00:01:29,590
work with one or more incompatible

32
00:01:29,590 --> 00:01:32,950
classes. The adoptee, by referencing and

33
00:01:32,950 --> 00:01:35,010
calling methods on an adapter.

34
00:01:35,010 --> 00:01:38,350
Abstraction. Ah specific adapter is

35
00:01:38,350 --> 00:01:42,060
created for each specific adoptee. In our

36
00:01:42,060 --> 00:01:43,760
example, we would have a different

37
00:01:43,760 --> 00:01:46,000
specific adapter for reading Star Wars

38
00:01:46,000 --> 00:01:48,800
characters from a file versus from an a p

39
00:01:48,800 --> 00:01:52,130
i n point. Another option is to use a

40
00:01:52,130 --> 00:01:55,230
class, and after in this case, the client

41
00:01:55,230 --> 00:01:57,160
is calling a target classes particular

42
00:01:57,160 --> 00:01:59,290
method, but it wants to use a different

43
00:01:59,290 --> 00:02:01,720
implementation now. The adoptees

44
00:02:01,720 --> 00:02:05,110
incompatible method the adopter class

45
00:02:05,110 --> 00:02:08,100
inherits from both classes and overrides

46
00:02:08,100 --> 00:02:10,240
the some method call so that instead of

47
00:02:10,240 --> 00:02:12,410
doing what it did in a target class, it

48
00:02:12,410 --> 00:02:14,810
now calls the incompatible method and does

49
00:02:14,810 --> 00:02:17,400
any work necessary to make it compatible

50
00:02:17,400 --> 00:02:20,590
with the some method interface. We can't

51
00:02:20,590 --> 00:02:22,730
use this approach in C Sharp because we

52
00:02:22,730 --> 00:02:24,590
can't inherit from to implementation

53
00:02:24,590 --> 00:02:28,910
classes. However, what we can do in C

54
00:02:28,910 --> 00:02:31,270
Sharp is implement the target interface

55
00:02:31,270 --> 00:02:33,170
the client was calling. And rather than

56
00:02:33,170 --> 00:02:35,450
holding onto an instance of the concrete a

57
00:02:35,450 --> 00:02:38,910
daft DIY type we can inherit from it once

58
00:02:38,910 --> 00:02:41,490
again. The some method implementation in

59
00:02:41,490 --> 00:02:44,210
the adapter calls the incompatible method

60
00:02:44,210 --> 00:02:50,000
and does any necessary work to modify it to work with the some method interface

