1
00:00:01,020 --> 00:00:04,020
All right folks, welcome to the course.

2
00:00:04,020 --> 00:00:05,890
Over the next few clips, we're going to be

3
00:00:05,890 --> 00:00:08,370
discussing the prototype design pattern

4
00:00:08,370 --> 00:00:11,470
and its implementation, along with its use

5
00:00:11,470 --> 00:00:13,590
cases and application in real‑world

6
00:00:13,590 --> 00:00:17,110
development. This is going to include

7
00:00:17,110 --> 00:00:20,170
setting up a simple object class, creating

8
00:00:20,170 --> 00:00:23,210
an abstract prototype class, handling

9
00:00:23,210 --> 00:00:26,470
shallow and deep copying, using a

10
00:00:26,470 --> 00:00:28,950
prototype manager, and reviewing common

11
00:00:28,950 --> 00:00:31,030
use cases and applications of the pattern

12
00:00:31,030 --> 00:00:33,760
itself. As you might already know,

13
00:00:33,760 --> 00:00:35,620
designed patterns are classified into

14
00:00:35,620 --> 00:00:38,420
three different categories, Creational,

15
00:00:38,420 --> 00:00:41,300
Structural, and Behavioral, outlined by

16
00:00:41,300 --> 00:00:44,350
the Gang of Four's text on elements of

17
00:00:44,350 --> 00:00:46,960
reusable object‑oriented software. The

18
00:00:46,960 --> 00:00:48,910
prototype pattern falls into the

19
00:00:48,910 --> 00:00:51,790
Creational category. More specifically, it

20
00:00:51,790 --> 00:00:55,260
specifies the kinds of objects to create

21
00:00:55,260 --> 00:00:58,250
using a prototypical instance and creates

22
00:00:58,250 --> 00:01:02,140
new objects by copying this prototype.

23
00:01:02,140 --> 00:01:04,480
From a high level, this pattern allows a

24
00:01:04,480 --> 00:01:07,370
client to request a clone of an existing

25
00:01:07,370 --> 00:01:10,440
object from the object itself. On a

26
00:01:10,440 --> 00:01:12,750
smaller scale, using this pattern can cut

27
00:01:12,750 --> 00:01:15,220
down on your subclassing hierarchy by

28
00:01:15,220 --> 00:01:17,780
allowing you to create configurable clones

29
00:01:17,780 --> 00:01:21,170
of existing classes instead. We will talk

30
00:01:21,170 --> 00:01:24,030
more about specific use case criteria at

31
00:01:24,030 --> 00:01:26,340
the end of the course, but before we jump

32
00:01:26,340 --> 00:01:29,070
into any code, let's look at a UML diagram

33
00:01:29,070 --> 00:01:31,460
of the prototype pattern to get our heads

34
00:01:31,460 --> 00:01:34,570
around it in a more visual sense. Now this

35
00:01:34,570 --> 00:01:36,990
one is fairly simple. We have a prototype

36
00:01:36,990 --> 00:01:39,080
interface, which in our case is an

37
00:01:39,080 --> 00:01:41,550
abstract class, that has the blueprint

38
00:01:41,550 --> 00:01:44,730
Clone method for all our adopting classes.

39
00:01:44,730 --> 00:01:46,310
Then we have as many concrete

40
00:01:46,310 --> 00:01:49,330
prototypeable classes as we need, each one

41
00:01:49,330 --> 00:01:51,690
responsible for cloning and returning a

42
00:01:51,690 --> 00:01:54,380
copy of itself on command. Finally, we

43
00:01:54,380 --> 00:01:56,280
have a client, which makes the actual

44
00:01:56,280 --> 00:01:58,990
cloning request from an existing object

45
00:01:58,990 --> 00:02:01,690
that implements our prototype interface.

46
00:02:01,690 --> 00:02:03,740
In summary, you'll want to implement the

47
00:02:03,740 --> 00:02:06,600
prototype pattern when object creation,

48
00:02:06,600 --> 00:02:09,790
composition, and representation needs to

49
00:02:09,790 --> 00:02:12,180
be separate from a given system. And with

50
00:02:12,180 --> 00:02:14,040
that bit of theory, under our belts, we

51
00:02:14,040 --> 00:02:20,000
can safely move on to creating our example class and making it cloneable.

