00:00Welcome to Mastering JavaScript Design Patterns,
00:03a packed publication.
00:05I'm your host, Ben Fala, so let's jump right into it.
00:09In section number one, we're gonna go ahead
00:11and learn about how to create design patterns
00:14and be introduced to the topic as a whole.
00:17We're gonna ask ourselves what design patterns are
00:19and understand the answers to them.
00:21We're gonna also approach the first problem
00:24that we have in JavaScript,
00:25which is working with the global scope.
00:27We're gonna create a simple application
00:29that uses the global scope way too often.
00:32Once we do that, we're gonna try to solve the problem
00:35that we've created by introducing
00:37the object literal design pattern
00:39and namespace design pattern
00:41to help solve the problem of our over usage
00:43of the global scope.
00:46After we've done that,
00:46we're gonna move to a completely different approach,
00:49which is called the module design pattern,
00:51enabling us to create privacy inside of JavaScript.
00:55When completed with that,
00:56we'll move into the reveal pattern,
00:58which is an upgraded version of the module design pattern,
01:02enabling us to create a cleaner, easier to maintain code.
01:06And we'll wrap up the first chapter, this first section,
01:09by controlling the global access completely,
01:12creating the solution that will enable us
01:14not to access the global scope at all,
01:17unless we choose to.
01:18So it's gonna be a very interesting foray
01:20to the topic of design patterns.
01:23So let's jump right into it.
01:25All right, let's confront the reason why
01:27we're taking this title.
01:29And that's really design patterns.
01:32So let's understand what are they.
01:34Now, I'm sure you've heard of them previously,
01:36but design patterns in essence are something very simple.
01:41Their goal is to provide a solution
01:43to a common issue in software design.
01:45And that means is that a lot of developers
01:48encountered a problem or an issue,
01:51a conceptual issue in software design
01:54that needed a solution.
01:55And there were many solutions.
01:56And then one of those solutions
01:57became a really good solution.
02:00And then it got a name,
02:01and it got a way for us to represent that solution
02:05in one word,
02:06and that one word could represent now
02:08a lot of things that are actually happening
02:10behind the scenes.
02:11Now, if you worked ever with any programming language
02:14that has events,
02:15then an event on its own is a design pattern.
02:19By using events and saying the word event
02:21is very clear to people what it is
02:23once they know what it is
02:24without needing you to explain to them
02:26a lot of things.
02:28So design pattern has a few different
02:30usages really on one end,
02:32it provides a solution to a common problem
02:35and it also names that problem.
02:37Now, these patterns encourage users
02:40to reuse their design strategies.
02:43And that could be a positive
02:45and it could be a negative.
02:47It means that you need to think less
02:48about common problems
02:50because you have a common solutions to them.
02:52But with that said,
02:53sometimes those common solutions
02:54are just not appropriate.
02:56So it doesn't walk away from your need
02:58to know what you're doing,
03:00but it definitely makes your life way easier
03:02because the solutions or the choice of solutions
03:05for the most are there and available to you.
03:08Now, as we said previously,
03:11it creates a common vocabulary and structure,
03:14making it much easier for you
03:15to communicate with other developers
03:17and also for yourself,
03:19as you're working on a project,
03:20you don't have to think about
03:22all this pile of code and pile of structure
03:25because all that pile of structure
03:26is then it has a name,
03:28it has a way for you to reference it
03:30and talk about it and think about it as a whole.
03:33So design patterns give us a lot of things
03:35by creating solutions that are then
03:37more simple for us to then build upon them
03:39and create more complex architectures.
03:42So that's what design patterns are.
03:45Now, let's talk a little bit
03:46about what design patterns are not.
03:49Now, the first and foremost
03:51is it's not an exact solution to a problem.
03:54It's a theoretical solution
03:56or I would say a solution for a common problem.
03:59It is not a solution for a specific problem that you have.
04:02Many developers mistaken the goal of design patterns
04:07and they overuse them.
04:08They think everything needs to have a design pattern
04:11and that's not true.
04:12Design patterns are not intended to be overused
04:15or used just as a default instead of a strategy.
04:18So it's really important for you to realize that
04:21and not try to lean on a specific design pattern
04:24to solve very specific problems.
04:27Instead of that, get to know design patterns
04:30and integrate them and weave them into your workflow
04:33without using them as a crotch
04:35or using them as a way to avoid solving a problem.
04:40All right, so they do not replace
04:41and that really connects to that.
04:43They do not replace a good design strategy.
04:46I can't not say this more strongly.
04:48I've met a lot of developers
04:49that are incredibly intelligent
04:51but because of their overuse and overreliance
04:54on design patterns, their code was impossible to read.
04:58And again, and it really captures that problem
05:01is that design patterns could lead you
05:03to very inefficient solutions
05:05if you lean on them too heavily.
05:07All right, so that's about what design patterns are
05:10and what they're not.
05:11And I wanna talk a little bit more
05:13about what makes something a pattern.
05:15So first of all, a pattern needs to have a purpose
05:18and a very clear purpose of what is that pattern used for?
05:21What is that design pattern intended for?
05:24It cannot be a shop all used for many things.
05:26It needs to solve a very specific problem
05:28and it needs to be very useful
05:30and it needs to prove its usefulness throughout.
05:34Beyond that, it needs to be applicable.
05:36So if it's a really great design pattern
05:38but is rarely or ever used,
05:39then it would probably not be called a design pattern
05:43because every single thing we do as a design pattern,
05:45it's just not a formal design pattern.
05:48And that really leads us to the fact
05:49where you could create your own new patterns.
05:52They wouldn't really be called design patterns
05:54because they would be probably called proto design patterns
05:58because they're not really accepted by the community
06:00and a big part of making a design pattern
06:03actually accepted or called a design pattern
06:07and has a name and people accepting it
06:08is really usage of it, a large usage of users
06:11and an acceptance of the community of developers.
06:15Okay, so that's really what makes a pattern.
06:17And I wanna just talk about just in general,
06:19just a little bit of an overview
06:20which is really gonna lead us
06:22into the following few sections.
06:24So the common types of patterns are really invented
06:28and really the birth of design patterns
06:30was born roughly around 1995
06:33when a group of four developers wrote a book
06:36about design patterns and introducing it into the world.
06:39They were nicknamed the gang of four.
06:42You could read up on them online
06:43or in the references inside of the document
06:45that provided in this title.
06:48But as these gang created their title,
06:52they introduced the world 23 design patterns
06:55that they came up with.
06:56And through those design patterns,
06:58they split them into the most common patterns
07:01until today are used in the object oriented programming.
07:06One was the creational patterns
07:08and the creational patterns were focused
07:10on the process of creating new instances.
07:13Really, if it's in many object-oriented programming languages,
07:17we're really talking about the relationship
07:18of classes to their creation.
07:21In JavaScript, it's a little bit different
07:23because JavaScript does not have classes,
07:25but it's the process of the creating the objects
07:28in JavaScript, so that's the creational patterns.
07:30And that's the first group.
07:32The second group, and by the way,
07:33the first group, the creational patterns
07:35are gonna be our main topic of section two.
07:39In section three, we're gonna look
07:41into the structural patterns
07:42and the structural patterns really go into
07:44the structure of classes or in the case of JavaScript,
07:48of objects, and how do you organize your code structurally
07:52to make them the most efficient,
07:54specifically to patterns.
07:55And we're gonna look at the different patterns
07:56at different patterns that relate
07:58to structural patterns in section three.
08:01And in section four, we're gonna move on
08:03to behavior patterns.
08:04And the behavioral patterns are really
08:06when objects are interacting with other objects
08:10and what are the best ways for us
08:12to create those type of interactions,
08:14such as, for example,
08:15we talked about events previously.
08:17And we're gonna look more deeply
08:19in section four of those behavioral patterns.
08:22So those are the three common categories
08:25and you can definitely have others.
08:26It doesn't have to sit inside
08:28and there's definitely patterns that could overlap
08:30between different patterns
08:31and there's definitely patterns
08:32that might need the usage of other patterns
08:35to be able to be implemented, okay?
08:37So that's really it about the core structure
08:41of this course, really, in a way,
08:42and this foray to what are design patterns.
08:46In the next lesson, what we're gonna do
08:47is we're gonna look at a problem.
08:49We're gonna forget about this conversation
08:51about patterns for a few lectures
08:53and we're gonna go right into our code editor
08:55and we're gonna talk about the problem
08:56with the global scope
08:57and we'll see you in the next lecture
08:59when we do that.