Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the factory model of C++

Shulou Source: shulou.com Published: 2022-06-02 02:47:23 10月05日 Update

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

Tags: Factories patterns caching code knowledge content articles Apple not easy value functions other types that is interfaces easy to operate articles methods easy to understand more read Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Microsoft Shulou Technology MySQL NVidia