Design Patterns - Factory Method Pattern Explanation and Implementation in C++

preview_player
Показать описание

►Lesson Description: In this lesson I teach you about a creational design pattern to have a single point in which you allocate objects at run-time. This is the factory method (or factory function), which takes advantage of inheritance based polymorphism to create the correct object at run-time and return it to the user.

00:00 Factory method and definition
1:25 Goal of the factory method pattern
2:37 Inheritance based polymorphism
3:40 Start of implementation with interface
4:50 Creating derived classes
5:58 Creation of our factory
9:15 Confirming the factory works in GDB
10:50 Refactoring our factory arguments with enum class
14:35 Returning a smart pointer from our factory
16:12 Confirming no memory leaks with valgrind
17:30 Recap of source code and pattern
18:00 Pros and cons of the pattern

►Please like and subscribe to help the channel!
Рекомендации по теме
Комментарии
Автор

Your video is probably one of the best I have found in how to use design patterns in C++. It is really clear, and the fact that you show in real time what you are doing really helps follow the content.

anhurtjv
Автор

Thank you for explaining these patterns so clearly and for keeping it simple. Other sources I tried made them seem very complicated and I almost gave up.. thankfully I came across your channel! I can't thank you enough.

stevea.b.
Автор

amazing. I'm so lucky to have the chance to watch your

k
Автор

Man i just got the understanding of Factory Design pattern after watching it so easily
Thanks a lot 🙏

bharatpatidar
Автор

amazing as always = thank you so much Dr. Mike

sallaklamhayyen
Автор

Can you please make a series on the how to make use of debugger to the fullest. I have never seen or even knew that we can view vtable using it. Or if you could recommend any good resource for it.

anuragmeshram
Автор

Hallo Mike,
I understood the code you implemented, but I do not understand why you have to it that way. Why did you have to go through a factory method to create those objects?
I do not get the point of factory method. Layman terms could also help me when explaining.
Merry Christmas

blaisofotso
Автор

Absolutely loved your teaching style! 🙌 Thanks for the cool tip: --tui

riamuglihal
Автор

Thanks for the clear explanation and great content. According to refactoring guru, the design pattern "factory method" would have a creator, concrete creators, product, and concrete products. In the example you provided, MakeGameObjectFactory seems to be an object creation function that abstracts away the object creation process and provides an easier way to create objects. I'm wondering if this is a simplified variation of the factory method, or if this still aligns well with the standard factory method? Thanks.

AnthonyWang-ri
Автор

_thank you thank you thank you_ for the clear explanation

essmunson
Автор

Can we keep factory method as static class method and keep class constructor private? so only from factory method we can create instance of class.

maheshshinde
Автор

Curious, Is there any reason to use shared_ptr? in general, by default people use unique_ptr.

Praveer
Автор

Does this pattern have to use heap allocation to work

windowsbuilderthegreat
Автор

isn't it, same as command pattern ?

tanveerasif