摘要
模板方法是设计模式中一种典型的设计范式,传统上是利用面向对象编程技术的多态属性实现的,文章应用泛型编程技术来实现模板方法设计模式。这种实现方式舍弃了面向对象编程技术中基于继承的基类,派生类的虚函数机制,免去了在程序运行过程中虚函数二次寻址的代价。在保留设计模式中程序修改扩展弹性的同时,降低了程序运行负载,提高运行速度,展现出一种泛型编程技术不同于传统的应用场景。
The template method is a representative pattern in design patterns.Traditionally,it is implemented by polymorphic attributes of object oriented programming technology.This paper introduces a method that implements the template method pattern by generic programming.This method of implementation abnegates the inheritance based virtual function mechanism which is the pivotal conception in object oriented programming,and avoids the expense for the second function addressing of virtual function in program running.The template method pattern implemented by generic programming not only reserves the flexibility for program extending and amending,but also improves the speed of program executing,demonstrating another scene of application of generic programming which is different from the traditional.
作者
余建华
赵晓莲
Yu Jianhua;Zhao Xiaolian(The 28^th research institute of China electronics technology group corporation,Nanjing,Jiangsu 210007,China)
出处
《计算机时代》
2019年第5期41-45,49,共6页
Computer Era
关键词
面向对象编程
泛型编程
模板函数
模板方法
设计模式
object oriented
generic programming
template function
template method pattern
design patterns