摘 要: 由于抽象工厂模式有利于达到高内聚低耦合的设计目的,因此在软件设计中得到广泛应用。但抽象工厂模 式的传统实现方式在处理具体产品构造函数参数不同、异类组合、具体产品数量繁多的情况时,都显得很繁琐、很困 难、复用性很低。针对这一问题,本文以抽象工厂模式为例,应用C++11新标准和泛型编程技术,提出一种C++11可 变参数泛型抽象工厂的实现方式。实验结果表明,该方式比传统实现方式更为简洁高效、复用性更强,优雅地实现了对 产品类型可变、参数可变、异类组合的支持。该实现方式及代码具有实用性,可应用到软件项目中。 |
关键词: C++11;泛型;可变参数;抽象工厂;设计模式 |
中图分类号: TP311.1
文献标识码: A
|
|
The Implementation of the Variable Parameter Generic Abstract Factory in C++11 |
MIN Jun,LUO Hong
|
( Yibin University, Yibin 644000, China)
|
Abstract: As the abstract factory pattern is conducive to the achievement of high cohesion and low coupling design,it has been widely applied in software design.But the traditional implementation models of the abstract factory design pattern are cumbersome and difficult with poor reusability,when dealing with the concrete product constructor of different parameters,heterogeneous combination and miscellaneous concrete products.Focusing on the problem and taking the abstract factory as an example,the paper adopts the new C++11 standards and generic programming technology to present an implementation model of the C++11 variable parameter generic abstract factory.Experimental results show that this model is more concise and more efficient with better reusability than the traditional implementation models.This model gracefully implements the support for variable product types,variable parameters and heterogeneous combination.With good practicability,the implementation model and its code can be applied in software projects. |
Keywords: C++11;generic;variable parameter;abstract factory;design pattern |