In this video Emmanuel Henri explains the factory pattern with an example.
- [Instructor] The factory pattern is great…when you want to create say a mechanism…to create other objects.…A good example would be a factory for creating cars.…This can be useful when you want a factory to handle…most of your classes and then simply use…this factory method to create new objects.…Again this is best demonstrated…in a code example so let's go back…to our code here in the index.js…and what we'll do is remove a few things so,…I'm going to remove the let instance…and then the SUV and just leave…the honda log here.…
We're going to need that.…And then inside of our constructor…let's remove the if instance and the else.…So you should only have this code…at the end once we've removed everything…so the console.log and then the class car…with the constructor and only three items…that are being initiated here.…Alright so once you have that,…let's go ahead and create the factory.…So we'll create a factory and you do…this with the keyword class.…
And we'll call this carFactory.…And inside of our factory we'll have a function…
- What's a pattern?
- What's the role of callbacks?
- Creational patterns, including Singleton and Factory
- Structural patterns, including model-view-controller
- Behavioral patterns, including Memento and Mediator
Skill Level Intermediate
2. Creational Patterns
3. Structural Patterns
4. Behavioral Patterns
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.