How to realize the factory model of C++
This article mainly introduces the relevant knowledge of how to realize the factory model of C++. The content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to realize the factory model of C++. Let's take a look.
Simple factory pattern: creation pattern / static factory method pattern, not belonging to 23 design patterns
Is to actually construct a factory class (high cohesion, if newly added, you must modify the original code instead of expanding the original code), which is not easy to expand.
Function: use one class to create other classes, but all have an interface (programming for abstract classes)
(1), code implementation
# include#includeusing namespace std;class Fruit {public: virtual void getFruit () = 0; private:}; class Banana: public Fruit {public: virtual void getFruit () {cout