#include <iostream>
enum CTYPE {PRODUCTA,PRODUCTB};
class Product{
public:
virtual void func() = ;
virtual ~Product(){};
}; class ProductA : public Product{
public:
void func(){
std::cout << "create ProductA..." << std::endl;
}
}; class ProductB : public Product{
public:
void func(){
std::cout << "create ProductB..." << std::endl;
}
}; class Factory{
public:
static Product* createProduct(enum CTYPE ctype){
if(ctype == PRODUCTA)
return new ProductA;
else if(ctype == PRODUCTB){
return new ProductB;
}else
return nullptr;
}
}; int main(){
Product* p = Factory::createProduct(CTYPE::PRODUCTA);
p->func();
return ;
}

interview :C++ More articles on the implementation of factory mode

  1. java Interview questions ---- The factory model is in order ( The interview asked more )

    In an interview, I learned the importance of factory mode in practical application , It can be said that the application of factory mode can be seen everywhere , Here is Baidu Encyclopedia's introduction to the factory model Factory pattern is the most commonly used instantiation object pattern , It's a factory approach new A mode of operation . The famous Jiv ...

  2. From the interface 、 From abstract classes to factory patterns to JVM To sum up some problems

    It is said that , Write your own code ,6 It's someone else's code after a month …… review ! review ! review ! The knowledge points involved are summarized as follows : Why interface ? The difference between interface and abstract class Summary of the simple factory model Java in new and newInstance The difference between J ...

  3. Android Design patterns ( Children under five )-- Simple factory model

    1. Ask this question during the interview : stay ListView Of item Applet . Many different display styles . Or is it , In order to better maintain , Different styles , What to do ? What I think of immediately is the factory model , utilize project, To write ViewFa ...

  4. 【Unity And 23 Design patterns 】 Abstract factory pattern (Abstract Factory)

    GoF In the definition of : " Provide an object that can establish an entire group or association , You don't have to specify their concrete classes ." It means Different subclasses of abstract classes are generated according to different execution environments Abstract factory pattern is often involved in the interview Here's an example ...

  5. Design patterns | Simple factory model (static factory method)

    You ought to read all the books , It's more scientific to start blogging again , Will have a more comprehensive understanding . But I've decided to update my blog regularly , I can only read through one design pattern and write one article . I forced myself to think , It's not the end of it , At least type the code yourself . ...

  6. Design pattern Factory The benefits of the factory model

    The most intuitive advantage is bragging , It's better to look at objects than to create them good-looking In general , We create objects using new. Sample sample=new Sample(); However , It's going to be more complicated than that , for instance Sa ...

  7. Good code is good ? Simple factory model C#

    Or those words : knowledge has no limit , Keep improving Ten years of Hedong , Ten years in Hexi , Don't deceive young people into being poor Education represents your past , Ability represents your present , Learning represents your future I don't say much nonsense , Go straight to the point : Now I'll give you an interview question , as follows : Please use C++,C#,Ja ...

  8. Spring Study 13- in IOC( Factory mode ) and AOP( The proxy pattern ) Detailed explanation of

    We are using Spring Frame the process , It's just for the use of IOC, Dependency injection , and AOP, Section oriented programming , These two are Spring Soul . The main design patterns used are factory pattern and agent pattern . IOC It's a factory model reference : Design patterns - ...

  9. as3 The factory model of design pattern misuse

    I haven't written a diary about technology for a long time , In a hurry , Two lazy , Third, I'm not aware of this monotonous life . In fact, I've wanted to write this diary for a long time , At the beginning of the project , Take the students . I often see that kind of misuse of design patterns . One side , Company interviewers like to ask about design patterns , another ...

  10. Adapter 、 Factory mode 、 Thread pool 、 Thread group 、 The mutex 、Timer class 、Runtime class 、 Singleton design pattern ( Twenty-four )

    1. Multithreading approach * Thread There are two ways * 1.yield Give up CPU, Also known as comity thread * 2.setPriority() Set the priority of the thread * The highest priority is 10,Thread.MAX_PRIORI ...

Random recommendation

  1. centos Partition

    /boot : Used to store and Linux The system starts the relevant program , For example, start the boot loader , The recommended size is 100MB . /usr : For storage Linux Applications in the system , There are a lot of relevant data , The suggestion is greater than 3GB above ...

  2. Java Basic data type ( Information is a must for beginners )

    Variable is to apply memory to store values . in other words , When creating variables , Need to apply for space in memory . The memory management system allocates storage space for variables according to their types , The allocated space can only be used to store this type of data . therefore , By defining different types of variables , Can be in memory ...

  3. php Memcache/Memcached Operation manual

    php Memcache/Memcached Use the tutorial Memcache and Memcached It's a thing , It's just php If the extensions used in are different , 2009 It's been rich around the year memcache The usage and performance of , Write the ...

  4. Homework one : Create a personal technology blog 、 Self introduction. 、 ordinary C Program

    year 9 month 14 Noon 12 spot : One . primary coverage   Build a personal technology blog ( Blog Garden www.cnblogs.com) I will submit my homework by blogging this semester , actually , The ultimate goal is to hope that students can record our whole learning process in the form of blog ...

  5. AYUI Rapid development of 2016-6-29 , All free ,WPF The universal road dream opens

    Download the development template : download AYUI 6 month 29 The date of , Free use , No authorization required , Remove all restrictions , Care for developers , Don't ask for donations , As long as you can earn money from your personal work , You don't owe me . I hope everyone can develop WPF Things that are Use the tutorial , The download file above ...

  6. Machine learning practice 5:k-means clustering : Two points k Mean clustering + Examples of geographic clustering

    k- Mean clustering is a kind of unsupervised learning , Input must specify the number of cluster centers k.k Mean is clustering based on similarity , Divide a cluster of instances without labels into one category . One classical k- Mean clustering Ideas : 1 Randomly create k A center of mass (k Must specify , Two dimensional is easy to determine ...

  7. ecshop stay nginx Load balancing is realized under the environment

    ecshop The function of load is very weak . When your IP Ten thousand an hour IP. If bandwidth and server hardware are limited . Your server will crash soon . Hang up the website . To enhance ecshop Ability in load balancing . We can ...

  8. Ext &amp; Java Save pictures on it Demo

    Ext & Java Save pictures on it Demo Ext <html> <head> <script id="microloader" type=&q ...

  9. Spring Chapter 9 【Spring And Hibernate Integrate 】

    Preface I've learned how to use Spring And Struts2 Integration , This blog mainly explains how to use Spring Yes Hibernate Integration Spring and Hibernate The key to integration : SessionFact ...

  10. prohibit WORDPRESS The way to search on the website

    If we want to ban on-site search , After all, it will be MYSQL Increased burden , We can ban it , And then using a third-party search component . For example, baidu station search or 360 On-site search . function fb_filter_query( $quer ...