1

00:00:00.06 --> 00:00:01.09

- [Instructor] Now, we can't have



2

00:00:01.09 --> 00:00:03.07

a conversation on design patterns



3

00:00:03.07 --> 00:00:07.04

without at least mentioning the Gang of Four.



4

00:00:07.04 --> 00:00:09.05

Now who are this Gang of Four?



5

00:00:09.05 --> 00:00:12.05

It was four software engineers, computer scientists,



6

00:00:12.05 --> 00:00:16.08

that wrote a book that revolutionized how we write code



7

00:00:16.08 --> 00:00:19.00

using object-oriented programming.



8

00:00:19.00 --> 00:00:22.02

Again, they were computer scientists first and foremost,



9

00:00:22.02 --> 00:00:23.07

but they also were authors.



10

00:00:23.07 --> 00:00:27.00

And they wrote a book called, "Design Patterns:



11

00:00:27.00 --> 00:00:30.09

"Elements of Reusable Object-Oriented Software."



12

00:00:30.09 --> 00:00:35.09

Now this is the book, in my opinion, that changed OOP.



13

00:00:35.09 --> 00:00:39.04

It introduced object-oriented programming,



14

00:00:39.04 --> 00:00:42.04

both the good and the bad.



15

00:00:42.04 --> 00:00:43.09

They didn't sugarcoat anything.



16

00:00:43.09 --> 00:00:47.00

They said exactly what was good about it,



17

00:00:47.00 --> 00:00:49.00

and all the problems that arose,



18

00:00:49.00 --> 00:00:51.01

and then they tried to talk about how to solve



19

00:00:51.01 --> 00:00:53.00

some of those problems.



20

00:00:53.00 --> 00:00:57.03

They focused on common object-oriented programming concerns,



21

00:00:57.03 --> 00:00:59.05

many we take for granted today



22

00:00:59.05 --> 00:01:02.04

because of the comments and the changes



23

00:01:02.04 --> 00:01:04.07

in the industry based on this book.



24

00:01:04.07 --> 00:01:06.04

Now design patterns themselves



25

00:01:06.04 --> 00:01:09.09

filled most of the content.



26

00:01:09.09 --> 00:01:13.02

And they broke those design patterns down into groups.



27

00:01:13.02 --> 00:01:14.04

The first group that we're going to talk



28

00:01:14.04 --> 00:01:16.09

about are the creational patterns.



29

00:01:16.09 --> 00:01:18.06

Now they are so called creational



30

00:01:18.06 --> 00:01:22.06

because as you might imagine, they create objects for you.



31

00:01:22.06 --> 00:01:25.00

The two most common are the Abstract Factory



32

00:01:25.00 --> 00:01:28.05

and the Factory pattern, but there's also a Builder pattern.



33

00:01:28.05 --> 00:01:30.08

And once you see this, if you don't know



34

00:01:30.08 --> 00:01:32.07

it's the Builder pattern, you immediately will say,



35

00:01:32.07 --> 00:01:34.05

"Oh, I've used that before."



36

00:01:34.05 --> 00:01:38.09

Because it's very, very prevalent in software engineering.



37

00:01:38.09 --> 00:01:42.03

One that Spring uses a lot is the Singleton pattern,



38

00:01:42.03 --> 00:01:43.09

though they don't leverage it in the same way,



39

00:01:43.09 --> 00:01:45.04

and we'll talk about that.



40

00:01:45.04 --> 00:01:47.06

But also the Prototype pattern.



41

00:01:47.06 --> 00:01:49.02

Now the second group that they broke



42

00:01:49.02 --> 00:01:52.02

these patterns up into were behavioral patterns.



43

00:01:52.02 --> 00:01:56.05

These were designed to focus on inter-object communication



44

00:01:56.05 --> 00:01:58.08

within the application run time.



45

00:01:58.08 --> 00:02:01.05

Now we're not going to talk about all of these on the course,



46

00:02:01.05 --> 00:02:03.06

but I at least want to bring up what the Gang of Four



47

00:02:03.06 --> 00:02:05.04

talked about in their book.



48

00:02:05.04 --> 00:02:07.02

And these are things like the Command pattern,



49

00:02:07.02 --> 00:02:11.07

and the Interpreter pattern, Mediator, Iterator, Observer.



50

00:02:11.07 --> 00:02:14.03

Then there's this concept of Chain of Responsibility



51

00:02:14.03 --> 00:02:16.00

and the Visitor pattern.



52

00:02:16.00 --> 00:02:19.03

And then there's Memento, State, Strategy,



53

00:02:19.03 --> 00:02:22.00

and the Template pattern, which is one that Spring uses



54

00:02:22.00 --> 00:02:24.09

all over the place, especially when dealing



55

00:02:24.09 --> 00:02:27.05

with remote calls.



56

00:02:27.05 --> 00:02:29.07

The final group that the Gang of Four talked about



57

00:02:29.07 --> 00:02:33.01

were the structural patterns, and these focused



58

00:02:33.01 --> 00:02:37.06

on object composition and interfaces.



59

00:02:37.06 --> 00:02:41.03

Things like the Adapter, the Bridge, the Composite,



60

00:02:41.03 --> 00:02:45.01

the Decorator, which is one that we'll see a lot in Spring.



61

00:02:45.01 --> 00:02:46.08

And Flyweight.



62

00:02:46.08 --> 00:02:48.06

And then there's the Facade and Proxy,



63

00:02:48.06 --> 00:02:50.06

both of which I'm sure you've used



64

00:02:50.06 --> 00:02:52.08

and are very common in the industry.



65

00:02:52.08 --> 00:02:55.03

Proxy is all over the place in Spring



66

00:02:55.03 --> 00:02:57.03

ever since Spring IV.



67

00:02:57.03 --> 00:02:59.07

Now these design patterns do have something



68

00:02:59.07 --> 00:03:02.02

to do with Spring, and I kind of alluded



69

00:03:02.02 --> 00:03:03.07

to some of these already.



70

00:03:03.07 --> 00:03:08.05

Spring inherently uses many of these classic patterns.



71

00:03:08.05 --> 00:03:10.09

But Spring also provides native support



72

00:03:10.09 --> 00:03:13.09

for using some of these in your code.



73

00:03:13.09 --> 00:03:17.04

And Java after all is an object-oriented language,



74

00:03:17.04 --> 00:03:21.00

and as such, Spring, which is based on Java,



75

00:03:21.00 --> 00:03:24.04

uses design patterns, and they're all over the place



76

00:03:24.04 --> 00:03:28.02

in code written in Java because they make sense.



77

00:03:28.02 --> 00:03:31.09

So Spring of course is going to use them to their advantage,



78

00:03:31.09 --> 00:03:35.00

and provide you a way to use them as well.



79

00:03:35.00 --> 00:03:36.05

And that's what we're going to focus on



80

00:03:36.05 --> 00:03:38.00

in the rest of this course.



