1 00:00:04,830 --> 00:00:07,360 Hello, I'm Craig and I'm a developer. 2 00:00:07,360 --> 00:00:08,025 In this course, 3 00:00:08,025 --> 00:00:11,490 we'll explore the wonderful world of software design patterns. 4 00:00:11,490 --> 00:00:13,900 You'll learn what they are, where they come from, and 5 00:00:13,900 --> 00:00:16,200 why you should be familiar with them. 6 00:00:16,200 --> 00:00:19,940 This course is going to be taught in a way that's programming language that agnostic. 7 00:00:19,940 --> 00:00:23,210 In other words, no matter what language you use, whether it be Java, Python, 8 00:00:23,210 --> 00:00:24,260 Swift, PHP, 9 00:00:24,260 --> 00:00:28,430 JavaScript, I'll explain design patterns using a shared terminology. 10 00:00:28,430 --> 00:00:29,990 Design patterns really are for everyone, and 11 00:00:29,990 --> 00:00:33,170 I'm super excited to help you to get to know them. 12 00:00:33,170 --> 00:00:36,660 Now before we get started, let's go over some quick ground rules. 13 00:00:36,660 --> 00:00:39,240 First there are speed controls on the video player. 14 00:00:39,240 --> 00:00:42,390 You should feel free to slow me way down or 15 00:00:42,390 --> 00:00:45,180 speed me up, and I won't be offended at all. 16 00:00:45,180 --> 00:00:49,090 Second there are detailed teachers notes accompanying most of these videos videos. 17 00:00:49,090 --> 00:00:52,530 Now I attempt to keep the notes up to date by answering your questions. 18 00:00:52,530 --> 00:00:54,320 So make a habit of checking them out. 19 00:00:54,320 --> 00:00:56,760 There's a good chance that you'll have the answer you're looking for 20 00:00:56,760 --> 00:00:58,750 sitting right there in the notes. 21 00:00:58,750 --> 00:01:01,360 Now if you don't find your answer in my notes, 22 00:01:01,360 --> 00:01:04,400 the Treehouse community is the next place to turn. 23 00:01:04,400 --> 00:01:07,090 Please, please, please ask questions. 24 00:01:07,090 --> 00:01:11,170 I guarantee you aren't the only one wondering what you're wondering. 25 00:01:11,170 --> 00:01:13,410 And by sharing, everyone wins. 26 00:01:13,410 --> 00:01:16,300 The community is extremely welcoming and responsive so 27 00:01:16,300 --> 00:01:18,880 you have absolutely nothing to lose by participating. 28 00:01:20,020 --> 00:01:24,030 All right, let's take a quick swing at breaking down what a design pattern 29 00:01:24,030 --> 00:01:25,650 actually is. 30 00:01:25,650 --> 00:01:28,920 We developers build all sorts of software to solve many different types 31 00:01:28,920 --> 00:01:29,709 of problems, right? 32 00:01:30,720 --> 00:01:34,420 Although our projects might be completely different from a business perspective, 33 00:01:34,420 --> 00:01:37,620 you know, you might be running a social media dating website, and 34 00:01:37,620 --> 00:01:40,380 I might be writing code that makes robots break dance. 35 00:01:40,380 --> 00:01:41,830 Despite those differences, 36 00:01:41,830 --> 00:01:46,930 we as developers run into similar problems crafting or designing our code. 37 00:01:46,930 --> 00:01:50,620 Now, don't confuse the word design with the actual aesthetic, you know, 38 00:01:50,620 --> 00:01:51,700 the look and feel. 39 00:01:51,700 --> 00:01:54,550 I'm talking about how we structure our applications code. 40 00:01:55,620 --> 00:01:58,900 Wouldn't it be great if there was a place to find the best practice when you run 41 00:01:58,900 --> 00:02:01,110 into one of those design conundrums? 42 00:02:01,110 --> 00:02:03,020 Well, that is exactly where design patterns come in. 43 00:02:04,090 --> 00:02:09,400 A pattern is a solution to a problem in a context, so 44 00:02:09,400 --> 00:02:11,930 this is the common definition given for one of these patterns. 45 00:02:11,930 --> 00:02:13,930 It's not the most helpful is it? 46 00:02:13,930 --> 00:02:15,940 It's pretty broad definition. 47 00:02:15,940 --> 00:02:16,650 Right? 48 00:02:16,650 --> 00:02:17,400 Let's talk about why. 49 00:02:18,450 --> 00:02:22,070 So the concept of having a defined pattern that provides a solution 50 00:02:22,070 --> 00:02:24,600 to a recurring problem in a specific context. 51 00:02:24,600 --> 00:02:27,930 Well, that comes from a totally different profession than software development. 52 00:02:27,930 --> 00:02:31,130 Design patterns actually come from the architecture world. 53 00:02:31,130 --> 00:02:33,430 You know like the designers of buildings and public spaces. 54 00:02:34,790 --> 00:02:38,060 In the late 1970s an architect named Christopher Alexander 55 00:02:38,060 --> 00:02:42,130 began exploring the possibility of providing a reference of proven ideas for 56 00:02:42,130 --> 00:02:44,650 constructing a living and working environment. 57 00:02:44,650 --> 00:02:48,680 The name of this book was called a Pattern Language, and it contained 58 00:02:48,680 --> 00:02:52,440 over 250 patterns that tackled all sorts of architecting problems. 59 00:02:52,440 --> 00:02:54,910 The patterns vary from designing a place for 60 00:02:54,910 --> 00:02:58,990 waiting and this could be applied to like a bus stop or a hospital waiting room. 61 00:02:58,990 --> 00:03:01,830 To patterns on how to maximize sunlight in a room and 62 00:03:01,830 --> 00:03:03,750 the problems that that extra sun might introduce. 63 00:03:04,810 --> 00:03:08,330 The idea here again is to produce a catalog of well defined 64 00:03:08,330 --> 00:03:12,370 improvement to work ideas for problems in a specific context. 65 00:03:12,370 --> 00:03:15,630 In other words, architects didn't have to come up with their own solution to each 66 00:03:15,630 --> 00:03:16,950 problem that they encountered, 67 00:03:16,950 --> 00:03:21,580 they had a catalog of a ready made solutions of patterns that they could use. 68 00:03:21,580 --> 00:03:24,410 And that's a pretty powerful concept. 69 00:03:24,410 --> 00:03:28,740 So powerful, in fact, that it caught the eyes of some software engineers. 70 00:03:28,740 --> 00:03:32,220 And those engineers, knowing that all developers could benefit from 71 00:03:32,220 --> 00:03:36,220 documenting well thought out solutions to the common problems that we all encounter 72 00:03:36,220 --> 00:03:38,600 attempted to use the same pattern structure. 73 00:03:38,600 --> 00:03:40,260 And it worked pretty well. 74 00:03:40,260 --> 00:03:42,250 So they started creating more patterns. 75 00:03:42,250 --> 00:03:44,550 They shared their thoughts at conferences and more and 76 00:03:44,550 --> 00:03:47,530 more developers grew interested in the concept. 77 00:03:47,530 --> 00:03:52,180 Soon the patterns proved useful in solving similar problems across diverse context, 78 00:03:52,180 --> 00:03:53,390 and they caught on like wildfire. 79 00:03:54,610 --> 00:03:57,150 In an effort to capture these emerging patterns for 80 00:03:57,150 --> 00:03:59,950 software engineers wrote a book to catalog them. 81 00:03:59,950 --> 00:04:04,050 This book has been incredibly influential in the craft of software development and 82 00:04:04,050 --> 00:04:06,640 more specifically object oriented design. 83 00:04:06,640 --> 00:04:10,700 This book is one of a handful that almost every developer has encountered at some 84 00:04:10,700 --> 00:04:12,330 point in their career. 85 00:04:12,330 --> 00:04:15,280 The four authors have been nicknamed the gang of four. 86 00:04:15,280 --> 00:04:18,320 Now, because of the book's super long title, this is 87 00:04:18,320 --> 00:04:23,310 often shortened to the gang of four book, and because we programmers are often known 88 00:04:23,310 --> 00:04:27,580 to shorten things to extremes, you'll often see this referred to as GoF. 89 00:04:27,580 --> 00:04:33,950 The Gang of Four book was published in 1994, more than two decades ago. 90 00:04:33,950 --> 00:04:37,840 But the 23 design patterns that it introduced are still very much alive and 91 00:04:37,840 --> 00:04:39,660 used in so many libraries and 92 00:04:39,660 --> 00:04:42,900 frameworks that you probably interact with them every single time you code. 93 00:04:44,290 --> 00:04:47,570 The book was written based on the programming languages of C++ and 94 00:04:47,570 --> 00:04:48,620 Smalltalk. 95 00:04:48,620 --> 00:04:51,630 But the patterns apply to all object oriented languages. 96 00:04:52,740 --> 00:04:56,470 The design patterns in this book are descriptions of communicating objects and 97 00:04:56,470 --> 00:04:59,790 classes that are customized to solve a general design problem 98 00:04:59,790 --> 00:05:01,910 in a particular context. 99 00:05:01,910 --> 00:05:05,340 The book does a great job of further specifying our original design pattern 100 00:05:05,340 --> 00:05:06,570 definition. 101 00:05:06,570 --> 00:05:10,130 Some languages approach object oriented programming in different ways and 102 00:05:10,130 --> 00:05:11,340 use different terms, for 103 00:05:11,340 --> 00:05:15,650 example, classes are part of a typical JavaScript programmer's vocabulary. 104 00:05:15,650 --> 00:05:18,920 If you're coming from a JavaScript background, you can think of a class 105 00:05:18,920 --> 00:05:21,940 kinda like a JavaScript object with properties and methods. 106 00:05:21,940 --> 00:05:25,040 Now there's a bit more classes than that, but that description should work for 107 00:05:25,040 --> 00:05:26,010 this workshop. 108 00:05:26,010 --> 00:05:27,000 Check the teacher's notes for more. 109 00:05:28,520 --> 00:05:31,560 Newer design patterns have emerged in the past two decades, and 110 00:05:31,560 --> 00:05:34,230 some of the original patterns have even been written 111 00:05:34,230 --> 00:05:37,450 directly into the programming languages as they evolve. 112 00:05:37,450 --> 00:05:40,700 There are many different programming design patterns, and they all have names 113 00:05:40,700 --> 00:05:45,150 like Singleton, Adapter, Observer and Mediator, and that's just to name a few. 114 00:05:45,150 --> 00:05:49,810 In this workshop, I'll introduce you to some of the most commonly used patterns. 115 00:05:49,810 --> 00:05:53,300 In the next video, I'll show you why it's pretty much a necessity to be just a wee 116 00:05:53,300 --> 00:05:54,190 bit familiar with them.