1
00:00:01,140 --> 00:00:03,630
Before we can do any object cloning, we

2
00:00:03,630 --> 00:00:06,500
need a prototype class object. The example

3
00:00:06,500 --> 00:00:08,080
scenario we're going to use for this

4
00:00:08,080 --> 00:00:09,980
course is that of a food ordering

5
00:00:09,980 --> 00:00:12,360
application where a handy feature would be

6
00:00:12,360 --> 00:00:14,420
the copying of favorited food orders

7
00:00:14,420 --> 00:00:16,710
customers may have already saved. The

8
00:00:16,710 --> 00:00:18,410
first thing we need to do is open up

9
00:00:18,410 --> 00:00:20,390
Visual Studio, and we're going to start

10
00:00:20,390 --> 00:00:23,850
ourselves a new console application. Make

11
00:00:23,850 --> 00:00:27,375
sure that C# is the language selected, now

12
00:00:27,375 --> 00:00:30,550
hit Next, and I'm going to name this

13
00:00:30,550 --> 00:00:35,320
Prototype Pattern and hit Create. Once

14
00:00:35,320 --> 00:00:37,310
that's all loaded up, let's go up to the

15
00:00:37,310 --> 00:00:41,700
Project menu and add a class. Make sure

16
00:00:41,700 --> 00:00:45,900
that C# is selected, and for the Name, I'm

17
00:00:45,900 --> 00:00:49,290
going to call this FoodOrder.cs and hit

18
00:00:49,290 --> 00:00:52,330
Add. Before we do anything, we do want our

19
00:00:52,330 --> 00:00:55,410
food order to be public, so let's add the

20
00:00:55,410 --> 00:00:58,440
keyword right onto the front of our class.

21
00:00:58,440 --> 00:00:59,860
Now our food orders are going to be pretty

22
00:00:59,860 --> 00:01:02,600
simple, but they do need a few properties.

23
00:01:02,600 --> 00:01:04,970
So let's start out by adding a public

24
00:01:04,970 --> 00:01:12,030
string customerName, a public Boolean

25
00:01:12,030 --> 00:01:16,110
called isDelivery, and a public string

26
00:01:16,110 --> 00:01:18,770
array that's going to handle our

27
00:01:18,770 --> 00:01:21,710
orderContents. I've made these all public

28
00:01:21,710 --> 00:01:23,490
here to keep things simple, but there's no

29
00:01:23,490 --> 00:01:25,190
rule saying you can't have private

30
00:01:25,190 --> 00:01:27,770
variables with public backing properties

31
00:01:27,770 --> 00:01:29,950
in this design pattern. That being said,

32
00:01:29,950 --> 00:01:32,480
let's also declare a class constructor

33
00:01:32,480 --> 00:01:36,490
that's going to set up all these values.

34
00:01:36,490 --> 00:01:39,845
We'll say public FoodOrder, and it's going

35
00:01:39,845 --> 00:01:45,240
to take in a string name, a bool delivery,

36
00:01:45,240 --> 00:01:51,690
and a string array contents. Perfect. Now

37
00:01:51,690 --> 00:01:55,850
we're just going to say this.customerName

38
00:01:55,850 --> 00:02:00,330
= name, this.isDelivery = delivery, and

39
00:02:00,330 --> 00:02:04,620
this.orderContents = contents. Go ahead

40
00:02:04,620 --> 00:02:07,350
and save that off. Now this should look

41
00:02:07,350 --> 00:02:09,500
pretty ordinary. And all we're really

42
00:02:09,500 --> 00:02:11,300
going to do to round out this clip is to

43
00:02:11,300 --> 00:02:14,080
add a debug method to help us visualize

44
00:02:14,080 --> 00:02:16,360
what's going on with our food orders once

45
00:02:16,360 --> 00:02:18,970
we start cloning them. So underneath our

46
00:02:18,970 --> 00:02:22,610
class constructor we'll say public void

47
00:02:22,610 --> 00:02:26,490
Debug, no parameters, and this is just

48
00:02:26,490 --> 00:02:27,400
going to have a bunch of

49
00:02:27,400 --> 00:02:36,550
Console.WriteLines. After the little

50
00:02:36,550 --> 00:02:38,250
header, I'm going to print out the name

51
00:02:38,250 --> 00:02:48,730
and delivery name. And Delivery, and we'll

52
00:02:48,730 --> 00:02:54,340
just put those values in this.customerName

53
00:02:54,340 --> 00:02:59,030
and this.isDelivery. Now for the order

54
00:02:59,030 --> 00:03:02,080
contents, we'll do one last

55
00:03:02,080 --> 00:03:06,438
Console.WriteLine, and in here we'll say

56
00:03:06,438 --> 00:03:09,835
Order Contents, and we'll just use the

57
00:03:09,835 --> 00:03:12,370
string.Join method because it's the

58
00:03:12,370 --> 00:03:15,440
easiest way to print this out in one line.

59
00:03:15,440 --> 00:03:18,590
We'll have each item separated by a comma,

60
00:03:18,590 --> 00:03:26,510
printed out in our orderContents array.

61
00:03:26,510 --> 00:03:29,440
Perfect. Now that that's set up, we do

62
00:03:29,440 --> 00:03:30,830
need to make sure that everything is

63
00:03:30,830 --> 00:03:33,510
working as expected. So let's go into our

64
00:03:33,510 --> 00:03:37,990
Program.cs, delete our Hello World, and

65
00:03:37,990 --> 00:03:42,060
let's create a new food order item. I'm

66
00:03:42,060 --> 00:03:44,640
going to have a header here that just

67
00:03:44,640 --> 00:03:47,450
makes sure that we know that this will be

68
00:03:47,450 --> 00:03:50,260
the original order item. And we'll create

69
00:03:50,260 --> 00:03:52,960
a new FoodOrder, we'll call this

70
00:03:52,960 --> 00:03:57,390
savedOrder, and we'll use our class

71
00:03:57,390 --> 00:04:00,080
constructor. I'm going to put it in as

72
00:04:00,080 --> 00:04:06,150
myself, it is for delivery, and I'll just

73
00:04:06,150 --> 00:04:09,730
create a new string array in line here,

74
00:04:09,730 --> 00:04:15,720
and I'll say I want a Pizza and a Coke.

75
00:04:15,720 --> 00:04:18,750
Awesome. Now we're just going to go ahead

76
00:04:18,750 --> 00:04:21,090
and debug this out, so we'll say

77
00:04:21,090 --> 00:04:28,800
savedOrder.Debug and save. If we run this

78
00:04:28,800 --> 00:04:30,890
now, we should see that the debug output

79
00:04:30,890 --> 00:04:33,610
with our order info, which is correct

80
00:04:33,610 --> 00:04:35,920
here. We've got an original order with my

81
00:04:35,920 --> 00:04:39,120
name, delivery Boolean, and order contents

82
00:04:39,120 --> 00:04:41,300
all printed out correctly. So that's

83
00:04:41,300 --> 00:04:44,030
working perfectly. With the Order class

84
00:04:44,030 --> 00:04:46,030
set up, we're now ready to implement the

85
00:04:46,030 --> 00:04:51,000
actual prototype cloning behavior, which we'll do in the next clip.

