From the course: Spring: Design Patterns
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Factory pattern in action
- [Instructor] So now that we've talked about Factory pattern, it's time to see it in action. If you open up the exercise files in your IDE, you'll see that I've already started the application for you by creating a Spring Boot starter and adding a couple of controller class as well as an interface and some implementations for our Factory. Let's take a look at the interface real quick. You'll see my Pet interface has several methods. Things that make sense when dealing with various types of pets that are really equal across all pets. And that's really how we want to start when dealing with the Factory. So we're going to create a new class called PetFactory. And this Factory we're going to want Spring to actually manage. So we're going to do an @Component annotation on it. Now there's going to be one method on our Factory. And that method is the Factory method itself. So it's going to return a Pet and it's going to be called createPet and it's going to take a string of animalType. Now…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
The Factory pattern4m 39s
-
(Locked)
Factory pattern in action5m 38s
-
(Locked)
The Builder pattern2m 55s
-
(Locked)
Builder pattern in action6m 1s
-
(Locked)
The Singleton pattern4m 1s
-
(Locked)
Singleton pattern in action4m 55s
-
(Locked)
The Prototype pattern4m 36s
-
(Locked)
Prototype pattern in action4m 59s
-
-
-
-
-