[1]梁 晓.一种基于C++11/17的自动注册工厂方法[J].大众科技,2021,23(4):13-15.
 An Automatic Registration Factory Method Pattern Based on C++11/17[J].Popular Science & Technology,2021,23(4):13-15.
点击复制

一种基于C++11/17的自动注册工厂方法()
分享到:

《大众科技》[ISSN:1008-1151/CN:45-1235/N]

卷:
23
期数:
2021年4
页码:
13-15
栏目:
信息技术与通信
出版日期:
2021-04-20

文章信息/Info

Title:
An Automatic Registration Factory Method Pattern Based on C++11/17
作者:
梁 晓
(广西广播电视大学,广西 南宁 530022)
关键词:
工厂方法C++11C++17
Keywords:
factory method pattern C++11 C++17
文献标志码:
A
摘要:
工厂方法模式作为最常用的创建型设计模式之一,被广泛运用在程序设计中。由于C++语言缺乏类似注入注解等标识接口,当工厂的产品构建方法因同一类型产品数量过多和产品构造参数不统一时,工厂函数就会变得繁琐,程序结构受到破坏,导致代码可读性变差并难以维护。文章介绍了利用C++11/17的新特性设计一种自动注册工厂方法,该方法支持产品自动注册和可变参数构造函数,能对工厂方法进行解耦,让代码结构更加简洁。
Abstract:
As one of the most used creational patterns, factory method pattern is widely used in program design. Because the C++ language lacks identification interfaces such as injection annotations, when there are too many factorys products and the product construction parameters are not uniform, the factory function becomes cumbersome, the program structure is destroyed, and result in the code readability deteriorating and difficult to maintain. This paper introduces the design of an automatic registration factory pattern using the new features of C++11/17. This method supports product automatic registration and variable parameter constructors, decoupling the factory method, and making the code structure more concise.

参考文献/References:

[1] [美]Erich Gamma,Richard Helm,Ralph Johnson,John Vlissides著,李英军,马晓星,蔡敏,等译. 设计模式: 可复用面向对象软件的基础[M]. 北京: 机械工业出版社,2007. [2] PURECPP. C++11实现一个自动注册的工厂[EB/OL]. http:// purecpp.org/detail?id=524,2016-01-22. [3] [美]Scott Meyers著,侯捷译. Effective C++ [M]. 北京: 电子工业出版社,2015. [4] ISO/IEC 14882. 2011, Information technology—programming languages—C++[S]. 日内瓦: 国际标准组织和国际电工委员会,2011. [5] ISO/IEC 14882. 2017 Programming languages—C++[S]. 日内瓦: 国际标准组织和国际电工委员会,2017.

备注/Memo

备注/Memo:
【收稿日期】2021-02-01 【基金项目】广西高校中青年教师科研基础能力提升项目(2020KY79005)。 【作者简介】梁晓(1981-),男,广西广播电视大学讲师,研究方向为信息技术和物联网应用技术。
更新日期/Last Update: 2021-07-14