摘要
主要利用Java泛型编程将泛型机制与设计模式有机地结合并加以优化和实现,提出一种基于Java泛型类型(generictype)的类型转换方案,在工厂设计模式或其他应用中可有效摆脱类型强制转换或向下类型转换的过程中极容易发生错误的情况。并针对Spring中强制类型转换工厂进行改进,在利用工厂获得某个类的实例时不需要硬编码的方式强制转换实例的类型。该改进提高了软件体系结构的可扩展性,为程序设计者提供了方便。最后,通过实际编程验证了该方案的有效性以及在类型转换中的优越性。
In this paper we mainly use Java generic programming to integrate the generic mechanism with design patterns in organic way and realise as well as optimise it.We propose a new class cast scheme which is based on Java generic types,to use the scheme in factory design pattern or other types of applications can effectively get rid of the error situations which are prone to incur in the process of either mandatory class cast or downward class cast.Moreover,we make the improvement in light of the mandatory class cast factory in Spring,when getting a certain instance of class with factory,it does not need the class of mandatory cast instance through hard code manner.The scheme improves the scalability of the software architecture,and provides convenience to programmers.Finally,the actual programming experiment results demonstrate its effectiveness and superiority of the scheme in class cast.
出处
《计算机应用与软件》
CSCD
北大核心
2012年第11期165-167,238,共4页
Computer Applications and Software
基金
四川省教育厅科研基金项目(10ZC025)
关键词
泛型
泛型编程
工厂模式
XML
Generic Generic programming Factory pattern XML