1
00:00:00,900 --> 00:00:01,910
[Autogenerated] before we round out the

2
00:00:01,910 --> 00:00:03,480
course, we're gonna talk about an

3
00:00:03,480 --> 00:00:05,380
important variant that you'll see quite

4
00:00:05,380 --> 00:00:07,490
often in the prototype pattern. And that's

5
00:00:07,490 --> 00:00:10,400
using a manager class. Essentially, all

6
00:00:10,400 --> 00:00:12,520
this does is keep track of a dictionary of

7
00:00:12,520 --> 00:00:15,120
prototype objects by key value pair,

8
00:00:15,120 --> 00:00:16,910
making it easier for client code to

9
00:00:16,910 --> 00:00:18,960
reference them and takes out the need for

10
00:00:18,960 --> 00:00:21,610
the objects to be created on the fly.

11
00:00:21,610 --> 00:00:24,260
Let's go back into our food order, and I'm

12
00:00:24,260 --> 00:00:25,960
gonna lay this out at the bottom of our

13
00:00:25,960 --> 00:00:30,360
name space, make myself some room, declare

14
00:00:30,360 --> 00:00:34,230
a new public class called prototype

15
00:00:34,230 --> 00:00:37,740
manager. We'll need a private dictionary

16
00:00:37,740 --> 00:00:40,400
here to hold our prototypes, So let's

17
00:00:40,400 --> 00:00:45,040
declare it as private Dictionary of String

18
00:00:45,040 --> 00:00:48,230
prototype. So we have key value pairs.

19
00:00:48,230 --> 00:00:52,180
Name this underscore prototype library,

20
00:00:52,180 --> 00:00:55,230
and I am gonna just initialize it so we

21
00:00:55,230 --> 00:00:57,860
don't have any errors. Now you can

22
00:00:57,860 --> 00:01:00,040
absolutely declare a class constructor

23
00:01:00,040 --> 00:01:02,370
here and initialized the prototype manager

24
00:01:02,370 --> 00:01:04,430
with the objects you want to store.

25
00:01:04,430 --> 00:01:06,020
However, that is overkill for this

26
00:01:06,020 --> 00:01:08,470
example, so I'm just gonna add an index or

27
00:01:08,470 --> 00:01:10,980
to the class and add the prototype objects

28
00:01:10,980 --> 00:01:14,550
manually when we need to. So it's a public

29
00:01:14,550 --> 00:01:18,640
prototype. This and We'll specify that

30
00:01:18,640 --> 00:01:23,180
strings are the keys and will say get. And

31
00:01:23,180 --> 00:01:24,590
every time we try and get this, we're

32
00:01:24,590 --> 00:01:30,590
gonna return. Prototype Library Forgiven

33
00:01:30,590 --> 00:01:35,320
Key. Now, when we try to set this well say

34
00:01:35,320 --> 00:01:41,450
prototype library done and and we'll use

35
00:01:41,450 --> 00:01:44,650
the key supplied and whatever value

36
00:01:44,650 --> 00:01:46,750
perfect. That's pretty much all we need

37
00:01:46,750 --> 00:01:48,960
for the basics of the manager class. Let's

38
00:01:48,960 --> 00:01:52,760
go back to our program. And underneath all

39
00:01:52,760 --> 00:01:55,610
are shallow and deep copying logic. Let's

40
00:01:55,610 --> 00:02:01,790
create a new prototype manager. I'm gonna

41
00:02:01,790 --> 00:02:04,910
create an order and I'm gonna add it or

42
00:02:04,910 --> 00:02:08,280
index it by a date string and we'll just

43
00:02:08,280 --> 00:02:13,300
say 23 2020. And this is gonna be a new

44
00:02:13,300 --> 00:02:16,560
food order and we'll say, This is gonna be

45
00:02:16,560 --> 00:02:22,460
for Steve. He's gonna pick it up. Sora is

46
00:02:22,460 --> 00:02:28,570
delivery is false for his order contents.

47
00:02:28,570 --> 00:02:30,880
Let's see what a Steve want. He wants a

48
00:02:30,880 --> 00:02:37,480
chicken parm and a root beer. And for the

49
00:02:37,480 --> 00:02:44,800
order, I d. Will say New order info. 8912

50
00:02:44,800 --> 00:02:48,400
Let's add a consul right line here that we

51
00:02:48,400 --> 00:02:50,510
know that we're grabbing this and this is

52
00:02:50,510 --> 00:02:53,470
our manager clone. We'll create a new food

53
00:02:53,470 --> 00:02:59,240
order. We'll call it Manager order

54
00:02:59,240 --> 00:03:03,170
explicitly cast it and then grab the order

55
00:03:03,170 --> 00:03:11,810
we want by key and called Deep Copy. It's

56
00:03:11,810 --> 00:03:16,740
also debug our manager order. Save it off,

57
00:03:16,740 --> 00:03:19,800
and I'm actually gonna comment out some of

58
00:03:19,800 --> 00:03:22,120
our previous code just so we can see the

59
00:03:22,120 --> 00:03:24,720
output a little clear. It's getting a bit

60
00:03:24,720 --> 00:03:32,730
cluttered. As we can see, the output is as

61
00:03:32,730 --> 00:03:34,930
we expect. We have a deep clone of our

62
00:03:34,930 --> 00:03:37,940
Steve order, and I'd say that this

63
00:03:37,940 --> 00:03:40,110
approach is actually going to scale fairly

64
00:03:40,110 --> 00:03:42,320
well with a large amount of prototype

65
00:03:42,320 --> 00:03:44,590
objects, especially if you passed in the

66
00:03:44,590 --> 00:03:46,870
orders to the pro tape manager on

67
00:03:46,870 --> 00:03:49,980
Initialization. While not included in the

68
00:03:49,980 --> 00:03:52,820
original Gang of Four text, the object

69
00:03:52,820 --> 00:03:55,220
pool pattern works extremely well with

70
00:03:55,220 --> 00:03:57,910
prototype, especially if it has a manager

71
00:03:57,910 --> 00:03:59,980
class. Just some food for thought as you

72
00:03:59,980 --> 00:04:02,040
continue your journey with design

73
00:04:02,040 --> 00:04:04,340
patterns. An important side note here.

74
00:04:04,340 --> 00:04:06,700
We've only been using a single prototype

75
00:04:06,700 --> 00:04:08,730
object in this example, but it doesn't

76
00:04:08,730 --> 00:04:10,650
have to be that way. The whole point of

77
00:04:10,650 --> 00:04:12,960
having the abstract prototype class is

78
00:04:12,960 --> 00:04:15,230
that it can be implied to an indefinite

79
00:04:15,230 --> 00:04:17,420
number of objects that move may want to

80
00:04:17,420 --> 00:04:19,970
copy. Everything we've done will work just

81
00:04:19,970 --> 00:04:22,100
fine with a variety of different prototype

82
00:04:22,100 --> 00:04:24,250
objects, as long as they all inherit from

83
00:04:24,250 --> 00:04:29,000
the protect class and implement their own clothing and debug methods.

