摘要
针对简单工厂设计模式在编程应用中需要用到switch语句,不能动态添加分支以及在用C++语言编程时不能用字符串作为索引等问题,提出了一种利用C++标准库中Map容器来改造简单工厂设计模式的方法,替换switch语句,可以使用字符串作为索引,并且提出了动态添加分支的方法。编写了测试程序,检验了这种方法的有效性。
The switch words have to be used in the simple factory design pattern, and extend branch can' t be added to the pattern, and the string can' t be used as index in the C++, to solve those problem advanced a method to modify the simple factory design pattern by the Standard Template Library of C++, replace the switch words with the map container, which made it possible to use string as the index, and proposed a method to add branch. The test program was given to verify the reliability.
出处
《电脑编程技巧与维护》
2013年第4期25-26,共2页
Computer Programming Skills & Maintenance
关键词
设计模式
标准库
容器
design patterns
STL
container