摘 要: 抽象工厂模式在软件设计中应用广泛,但抽象工厂模式的传统实现方式存在诸多不足。随着技术的发 展,设计模式的实现方式也在不断改进。C++11新标准发布之后,涌现了许多改进方案。本文将在这些改进的基础之 上,使用C++11的lambda表达式、std::function类模板等新技术,通过数据结构和代码结构的优化等方式进一步改进 泛型抽象工厂设计,给出一种“新型泛型抽象工厂”的实现方式。实验结果表明,该方式更为简洁高效、复用性更强,优 雅地实现了对产品类型可变、参数可变、异类组合的支持。该实现方式及代码实用性较强,可以在软件项目中实际使用。 |
关键词: C++11;lambda;function;泛型;抽象工厂 |
中图分类号: TP311.1
文献标识码: A
|
|
Improvement of the Generic Abstract Factory Design through the Lambda Expression and the std::function Class Template |
MIN Jun, LUO Hong
|
( Library of Yibin University, Yibin 644000, China)
|
Abstract: The abstract factory pattern has been widely used in software design,but there are still some shortcomings in the traditional implementation of the abstract factory design pattern.With the development of technology,the implementation of design patterns is constantly improving.After the release of new C++11 standards,many improvement have emerged. Based on these improvements,this paper further improves the generic abstract factory design by adopting the new technology of the C++11 lambda expression and the std::function class template,optimizing the data structure and the code structure. The implementation model of New Generic Abstract Factory is proposed.Experimental results show that this model is more concise and efficient with better reusability.This model can gracefully implement the support to variable product types,variable parameters,and heterogeneous combinations.With decent practicality,this implementation method and code can be actually applied in software projects. |
Keywords: C++11;lambda;function;generic;abstract factory |