1
00:00:00,220 --> 00:00:01,420
[Autogenerated] The adapter pattern can

2
00:00:01,420 --> 00:00:03,990
also be applied to result types, not just

3
00:00:03,990 --> 00:00:06,970
the service providers in this case, to

4
00:00:06,970 --> 00:00:09,130
apply the pattern you must create or

5
00:00:09,130 --> 00:00:11,450
choose a common result type that your

6
00:00:11,450 --> 00:00:14,820
client expects to consume. Then you can

7
00:00:14,820 --> 00:00:17,390
inherit from this type and use composition

8
00:00:17,390 --> 00:00:20,140
to delegate calls made to the common type

9
00:00:20,140 --> 00:00:23,460
to the specific, incompatible type. Let's

10
00:00:23,460 --> 00:00:26,790
look at an example. Imagine if the file

11
00:00:26,790 --> 00:00:28,270
source that we've been working within our

12
00:00:28,270 --> 00:00:31,390
demo returned a list of characters instead

13
00:00:31,390 --> 00:00:34,770
of a list of person. Obviously character

14
00:00:34,770 --> 00:00:37,530
in person are very similar, but character

15
00:00:37,530 --> 00:00:41,640
has properties, full name and hair.

16
00:00:41,640 --> 00:00:44,960
However, person has properties, name and

17
00:00:44,960 --> 00:00:48,180
hair color. Our client could expects to

18
00:00:48,180 --> 00:00:51,080
work with a person type, so we'll use this

19
00:00:51,080 --> 00:00:54,190
as our adapter. In order to do so, we need

20
00:00:54,190 --> 00:00:55,950
to modify it to make its properties

21
00:00:55,950 --> 00:00:58,270
virtual. If we didn't have the ability to

22
00:00:58,270 --> 00:01:00,270
make this change, we would have needed to

23
00:01:00,270 --> 00:01:02,490
introduce a new type to serve as the

24
00:01:02,490 --> 00:01:05,010
wrapper and then modify our client could

25
00:01:05,010 --> 00:01:08,250
to work with this new type. Once we have

26
00:01:08,250 --> 00:01:10,710
identified a base adapter type that we can

27
00:01:10,710 --> 00:01:13,770
use in this case person, we need an

28
00:01:13,770 --> 00:01:17,130
implementation specific version of it. In

29
00:01:17,130 --> 00:01:19,920
this case, we are wrapping character in a

30
00:01:19,920 --> 00:01:22,570
person adapter, so we named the class

31
00:01:22,570 --> 00:01:26,090
character to person adapter. In it, we

32
00:01:26,090 --> 00:01:29,840
override calls to name and hair color, and

33
00:01:29,840 --> 00:01:31,840
we delegate thes properties to the

34
00:01:31,840 --> 00:01:34,630
character instances, full name and hair

35
00:01:34,630 --> 00:01:38,780
properties. Finally, we need to modify the

36
00:01:38,780 --> 00:01:41,450
character file source adapter so that it

37
00:01:41,450 --> 00:01:43,710
converts the character. Final sources

38
00:01:43,710 --> 00:01:46,940
returned collection of character instances

39
00:01:46,940 --> 00:01:50,140
into a sequence of type person,

40
00:01:50,140 --> 00:01:52,790
specifically of type, character to person

41
00:01:52,790 --> 00:01:56,040
adapter, which inherits from person.

42
00:01:56,040 --> 00:01:58,200
You'll find that the Link Select statement

43
00:01:58,200 --> 00:01:59,880
is very well suited to this kind of

44
00:01:59,880 --> 00:02:05,000
transformation in results, in short, clear code like you see here.

