I really appreciate this series. I hope you continue. Thank-you, you are a gentleman and a scholar.
@MikeShah Жыл бұрын
Thank you for the kind words :) More coming, observer is next!
@jeevanreddy7989 Жыл бұрын
Thank you Mike. I wasn't aware of this extensible factory pattern, prior to your lecture. It was amazing to learn this new pattern.
@MikeShah Жыл бұрын
Cheers, thank you for the kind words!
@raghul12082 жыл бұрын
thanks for this. Design patterns is something that is not emphasized as much in most curriculum. This playlist helped me a lot. thanks
@MikeShah2 жыл бұрын
You're most welcome!
@fishplantsandhamsters8391 Жыл бұрын
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?
@MikeShah Жыл бұрын
You could make it a template, though the extensible factory itself is able to make any type of object. Probably want to look at the 'abstract factory pattern' which allows you to make any type of concrete factory through a template.
@fishplantsandhamsters8391 Жыл бұрын
Thanks a lot for the reply! I will look into abstract factory pattern!
@fishplantsandhamsters8391 Жыл бұрын
One more thing, once I turn this factory class into an abstract class, It cannot be static anymore correct? Only classes that inherits it will be allowed to be static.
@MikeShah Жыл бұрын
@@fishplantsandhamsters8391 Can still have static members, just need an instantiation of the templated class before using it.
@whykozhoma10 ай бұрын
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().
@MikeShah10 ай бұрын
Cheers! From the actual extensible factory you can erase when you unregister objects. Otherwise, for the actual object, if they are heap allocated you can simply delete.
@tanveerasif5978Ай бұрын
Brilliant, thanks.
@MikeShahАй бұрын
Cheers!
@Itsme1n1ly Жыл бұрын
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
@MikeShah Жыл бұрын
With extensible factory you can add different types at run-time that you want to create.
@antonfernando84096 ай бұрын
Awesome Mike thanks. What are those 2 books you mentioned, if I heard right they seem some 20 years old.
@MikeShah6 ай бұрын
Modern C++ Design (Andrei Alexandrescu) and C++ API Design are the two I recommend. The latter I would recommend (C++ API Design), and uses C++11. Andrei's book is older, but still excellent for how to think about programming and policy-based design.
@jeevanreddy7989 Жыл бұрын
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.
@MikeShah Жыл бұрын
If static methods are being used, then you're right, probably best to make constructors private (i.e. effectively the factory design could be a singleton)
@jeordanisfiguereo75922 жыл бұрын
Very interesting. Thanks!
@MikeShah2 жыл бұрын
You're most welcome!
@nicolaschan33357 ай бұрын
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?
@MikeShah7 ай бұрын
You could do that, but in some ways you coupling some behavior to your factory. It's likely better you do so from main (or write a function that perhaps loads from a config file the plane, boat, etc.) if you plan on modifying the number of types you'll add. I'd say if you know exactly the fixed-set of types you'll have, extensible factory may be over-engineering, but if you want to be open to extension, it's not a bad idea.
@nicolaschan33357 ай бұрын
@@MikeShah Perfect explanation, thank you!
@mohammedaqdam17082 жыл бұрын
Interesting... Thanks
@MikeShah2 жыл бұрын
You are most welcome!
@MohamedHamzaoui4 ай бұрын
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.
@MikeShah4 ай бұрын
Could probably use a std::map to register new types at run-time, or a plugin system to take care of types loaded from a library.