Design Patterns - The Extensible Factory Pattern in C++ | Register Objects at Runtime

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

►Lesson Description: In this lesson I present to you an even more powerful version of the factory, in which you can extend and register objects at run-time in your factories. This makes your factories even more powerful, as clients can derive objects from your base classes, and then register them so they are created from the same factory you provide.

00:00 Introduction and refresher on factory pattern
1:10 Utilizing run-time polymorphism for factory
2:10 Extensible Factory allows you to add objects at runtime
3:20 Refresher of IGameObject
4:05 The Create Function in derived types
5:10 Example of a user created type derived from IGameObject
6:15 The Extensible Factory Interface
7:35 Using a callback function as a parameter in a map
8:33 Map storing how to create types
10:30 Implementation of Extensible Factory
12:17 Registering new types
13:00 Using our factory
14:25 GDB walkthrough to show working extensible factory
16:40 Conclusion and wrap up

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

Thank you Mike. I wasn't aware of this extensible factory pattern, prior to your lecture. It was amazing to learn this new pattern.

jeevanreddy
Автор

I really appreciate this series. I hope you continue.
Thank-you, you are a gentleman and a scholar.

WilhelmDrake
Автор

thanks for this. Design patterns is something that is not emphasized as much in most curriculum. This playlist helped me a lot. thanks

raghul
Автор

Thanks Mike for sharing your knowledge. Its very useful. Kudos to you.

Sorry to asking this. 1. What's the significant differences in using this extensible factory vs previous version of factory that has static getInstance()?
1. Register object
2. Statis is present in the derviced class
Anything? In terms of terminology, such as Extensibility, avoid duplication, reusability, and ???
2. Keeping static create in evry class makes the illusion of code redundancy, right? Whats your thoughts?

Bear with my questions

Itsmenly
Автор

Great lesson! I was thinking about making a factory pattern extensible after learning about it and this is exactly what i need to know!
My next question though is can this class be turned into something generic? like templatize it?

fishplantsandhamsters
Автор

Hi Mike! Really appreciate your lessons. Crazy that you can get such a quality product for free.
Question: what is the right way to avoid memory leaks in the extensible factory example, cuz clearly there is no delete for each object you return with Create().

whykozhoma
Автор

Mike...if the static methods are used to create a object, shouldn't the constructor of a class be private? In the examples used Ant, Plane classe have public constructors.

jeevanreddy
Автор

Since you have to register manually all objects, this can't be an OCP ready solution. Imagine that you have to use this factory in a library, it will be necessary to update the registration code whenever you add new type. The code must be closed for modification and open to extension.

MohamedHamzaoui
Автор

Awesome Mike thanks. What are those 2 books you mentioned, if I heard right they seem some 20 years old.

antonfernando
Автор

Thanks for the video!

I have a noob question - If I wanted to have some default object types (plane and boat for instance), instead of registering them in main.cpp like ant, do I just initialise them in the callback map in Factory.cpp after the callback map has been initialised?

nicolaschan
welcome to shbcf.ru