您的位置:山东大学 -> 科技期刊社 -> 《山东大学学报(工学版)》

山东大学学报 (工学版) ›› 2020, Vol. 50 ›› Issue (6): 48-58.doi: 10.6040/j.issn.1672-3961.0.2020.229

• 机器学习与数据挖掘 • 上一篇    下一篇

带特征指标约束描述的设计模式分类挖掘

肖卓宇1(),何锫2,陈果1,徐运标1,郭杰1   

  1. 1. 湖南工业职业技术学院信息工程学院, 湖南 长沙 410208
    2. 广州大学计算机科学与网络工程学院, 广东 广州 510006
  • 收稿日期:2020-06-07 出版日期:2020-12-20 发布日期:2020-12-15
  • 作者简介:肖卓宇(1979—), 男, 湖南长沙人, 硕士, 副教授, 主要研究方向为软件演化,程序理解,机器学习,数据分析等 E-mail:xzyxzy0770@126.com
  • 基金资助:
    湖南省自然科学基金科教联合资助项目(2020JJ7035);湖南省教育厅科学研究资助项目(19C0611);国家自然科学基金资助项目(61977018)

Design pattern classification mining with feature metrics constraints

Zhuoyu XIAO1(),Pei HE2,Guo CHEN1,Yunbiao XU1,Jie GUO1   

  1. 1. School of Information Engineering, Hunan Industry Polytechnic, Changsha 410208, Hunan, China
    2. School of Computer Science and Cyber Engineering, Guangzhou University, Guangzhou 510006, Guangdong, China
  • Received:2020-06-07 Online:2020-12-20 Published:2020-12-15

摘要:

为解决设计模式挖掘正确率较低的问题, 提出一种带特征指标约束描述的设计模式分类挖掘方法。归纳了47种特征指标, 给出了设计模式约束定义, 对设计模式特征进行了描述, 以Adapter模式、Command模式、Factory Method模式为例, 分结构型、行为型与创建型3类挖掘设计模式, 设计了3个基准系统与4个经典系统的设计模式挖掘试验。试验结果表明, 本研究方法对基准系统的Adapter模式、Command模式、Factory Method模式挖掘正确率为96.13%、91.67%、72.23%, 对经典系统挖掘正确率分别为84.3%、81.26%、73.17%, 与传统方法比较, 本研究方法取得了较好的效果。

关键词: 设计模式, 设计模式挖掘, 指标约束, 分类, 特征描述

Abstract:

To solve low accuracy for design pattern mining, a method for design pattern classification mining with feature metrics constraints was presented. 47 feature metrics information based on structural pattern, behavioral pattern and creative pattern was classified and summarized, and definition of design pattern were given, and features of design patterns were described, three benchmark systems and four well-known system experiments for design pattern mining were designed. Experimental results show that proposed method is effective, and the accuracy of the proposed method was 96.13%, 91.67%, 72.23% for Adapter pattern. Command pattern and Factory method pattern for three benchmark systems, and the accuracy of the proposed method is 84.3%, 81.26%, 73.17% for Adapter, Command and Factory Method of design pattern for four well-known systems, compared to well-known methods by experiment of design pattern mining, indicating the effectiveness of the proposed method.

Key words: design pattern, design pattern mining, metrics constraints, classification, feature description

中图分类号: 

  • TP311

图1

带特征指标约束描述的设计模式挖掘框架"

表1

特征指标表"

特征指标编号 特征指标名称 特征指标描述
F1 GetAllInterface(Class1, Class2, …, Classi, …) 取得接口信息, 其中Classi中下标i表示参与者序号
F2 GetAllClass(Class1, Class2, …, Classi, …) 取得类信息, 其中Classi中的下标i表示参与者序号
F3 HasGeneralization(Class1, Class2) Class1和Class2之间有泛化(Generalization)关系
F4 HasAssociation(Class1, Class2) Class1和Class2之间有关联(Association)关系
F5 HasAggregation (Class1, Class2) Class1和Class2之间有聚合(Aggregation)关系
F6 HasDelegation(Class1, Methodi, Class2, Methodj) Class1的Methodi方法代理了Class2的方法Methodj, 其中下标ij表示参与者Class中方法的序号
F7 NoHasAssociation(Class1, Class 2) Class1和Class2之间没有Association关系
F8 NoHasAggregation(Class1, Class2) Class1和Class2之间没有Aggregation关系
F9 HasCommonOperation(Class1, Class2, Method) Class1和Class2之间具有相同的Method
F10 HasAnnotation(Classi, Interfacej, Methodk) 对Class、Interface和Method进行标识, 其中下标ijk依次表示类、接口和方法的序号
F11 HasParameter(Method, Parameteri) Method可以拥有多个参数Parameteri, 其中下标i表示参数序号
F12 HasReturnValue(Methodi, Valuej) Methodi可存在返回值Valuei, 其中下标i表示参与者Method中方法的序号, j表示返回值Value的序号
F13 HasSameSignature(Methodi, Methodj) Methodi和Methodj具有相同的方法签名, 其中下标ij表示方法的序号
F14 HasCommonChildClasses(Class1, Class2, …, Classi…) 基类拥有i个派生类Classi, 其中下标i表示派生类的序号
F47 HasType(Variablei, Typej) 变量Variable的类型为Type, 其中下标i表示变量的序号, j表示Java变量的类型, 如整型、浮点型、字符型、日期型等

图2

设计模式特征指标定义"

图3

适配器模式"

表2

适配器模式特征指标描述"

序号 特征指标描述
1 HasClass(Client, Adaptee, Target, Adapter)
2 HasAssociation (Adaptee, Adapter)
3 HasDelegation (Adaptee, Specific_Request, Adapter, Request)
4 HasGeneralization(Target, Adapter)
5 HasNoCommonInterface (Adaptee, Specific_Request, Adapter, Request)
6 HasNoInheritance (Target, Adaptee)
7 HasNoInheritance (Adaptee, Adapter)
8 HasNoDirectAccess (Adaptee, Client)
9 HasOperation (Adaptee, Specific_Request)
10 IsConcrete(Specific_Request)
11 IsInterface(Target)

图4

命令模式"

表3

命令模式特征指标描述"

序号 特征指标描述
1 HasClasses(Client, Command, Invoker, Concrete_Command, Receiver) & & IsInterface(Command)
2 HasInheritance(Concrete_Command, Command)
3 HasAggregate (Command, Invoker)
4 HasDelegation(Concrete_Command, Execute, Receiver, Action)
5 HasAssociation(Concrete_Command, Receiver)
6 HasCommonOperation(Concrete_Command, Command, Execute)
7 HasAccess(Receiver, Client)
8 HasOperation (Concrete_Command, state)
9 HasOperation (Receiver, Action)

图5

工厂方法模式"

表4

工厂方法模式特征指标描述"

序号 特征指标描述
1 HasClasses (Concrete_Product, Product, Concrete_Creator, Creator) & & IsInterface(Concrete_Creator, Product)
2 HasInheritance(Concrete_Product, Product)
3 HasDependency (Concrete_Product, Factory_Method)
4 HasGeneralization (Concrete_Creator, Creator)
5 HasNoInheritance(FactoryMethod, Concrete_Product, Product)
6 HasCommonOperation (Concrete_Creator, Creator, FactoryMethod)
7 HasClass (Factory_Method)
8 IsAbstract(Factory_Method)
9 HasReturnValue (Factory_Method, Concrete_Product)
10 HasReturntype(Factory_Method, Product)

表5

基准系统参数"

基准系统名称 类的个数 千行代码数
JhotDraw 6.0b1 300 19
Apache ant v1.6.2 79 566 895
QuickUML2001 8 792 203

表6

基准系统设计模式挖掘"

设计模式 QuickUML 2001 Apache Ant 1.6.2 JHotDraw6.0 1b
基准 本研究 文献[11] 文献[12] 文献[20] 基准 本研究 文献[11] 文献[12] 文献[20] 基准 本研究 文献[11] 文献[12] 文献[20]
Adapter 38 37 34 32 36 65 63 57 59 62 34 32 29 27 31
Command 1 1 1 0 1 4 3 3 2 2 2 2 1 1 1
Factory 1 1 0 0 1 3 2 1 1 1 2 1 1 1 1

表7

3个基准系统平均正确率"

设计模式名称 类型 本研究 文献[11] 文献[12] 文献[20]
adapter 结构型 96.13 87.48 84.80 94.16
Command 行为型 91.67 75.00 33.33 66.67
Factory 创建型 72.23 27.77 27.77 61.10

表8

QuickUML中共享实例的设计模式"

设计模式名称 扮演角色 设计模式参与者位置
Command Command uml.ui.ExportAction
Receiver uml.ui.DiagramContainer
Invoke: java.io.File
Adapter Target uml.ui.ExportAction
Adapter uml.ui.DiagramContainer.OpenAction
Adaptee javax.swing.JMenuItem

表9

经典系统指标基准"

系统 KLOC 包数 类的数量 设计模式名称 标准设计模式基准数量 设计模式变体基准数量 共享模式实例基准数量
经典系统1 Adapter 4 2 1
127.52 8 182 Command 2 1 1
Factory Method 1 0 0
经典系统2 Adapter 6 2 2
150.82 11 243 Command 2 1 1
Factory Method 2 1 1
经典系统3 Adapter 8 4 3
210.65 23 382 Command 4 2 2
Factory Method 3 1 1
经典系统4 Adapter 15 7 5
365.87 64 662 Command 6 3 2
Factory Method 4 3 2

表10

经典系统设计模式挖掘"

测试系统 模式名 基准数 本研究 本研究方法正确率/% 平均正确率/%
标准 变体 共享 标准 变体 共享 标准 变体 共享
经典系统1 Adapter 4 2 1 4 2 1 100 100 100 100
Command 2 1 1 2 1 1 100 100 100 100
Factory 1 0 0 1 0 0 100
经典系统2 Adapter 6 2 2 6 2 1 100 100 50.0 83.3
Command 2 1 1 2 1 1 100 100 100 100
Factory 2 1 1 2 1 0 100 100 0 66.7
经典系统3 Adapter 8 4 3 7 3 2 87.5 75.0 66.7 76.4
Command 4 2 2 3 1 1 75.0 50.0 50.0 58.3
Factory 3 1 1 2 1 1 66.7 100 100 88.9
经典系统4 Adapter 15 7 5 13 6 3 86.7 85.7 60.0 77.5
Command 6 3 2 5 2 1 83.3 66.7 50.0 66.7
Factory 4 3 2 3 2 1 75.0 66.7 50.0 63.9

图6

基准系统与经典系统设计模式挖掘正确率对比"

表11

4个经典系统平均正确率"

设计模式名称 设计模式类型 平均正确率/%
Adapter模式 结构型 84.30
Command模式 行为型 81.26
Factory Method模式 创建型 73.17
1 LUCIA A D , DEUFEMIA V , GRAVINO C , et al. Detecting the behavior of design patterns through model checking and dynamic analysis[J]. ACM Transactions on Software Engineering and Methodology, 2018, 26 (4): 1- 41.
2 肖卓宇, 何锫. 多阶段可松弛的设计模式变体检测方法[J]. 华中科技大学学报(自然科学版), 2018, 46 (1): 26- 31.
XIAO Zhuoyu , HE Pei . Multi-stage relaxed detection method for variants of design pattern[J]. Journal of Hua zhong University of science and Technology (Natural Science), 2018, 46 (1): 26- 31.
3 MAYVAN B B , RASOOLZADEGAN A , EBRAHIMI A M . A new benchmark for evaluating pattern mining methods based on the automatic generation of testbeds[J]. Information and Software Technology, 2019, 59 (1): 60- 79.
4 肖卓宇, 何锫, 陈俊旭, 等. 设计模式变体检测研究[J]. 小型微型计算机系统, 2017, 38 (8): 1751- 1756.
doi: 10.3969/j.issn.1000-1220.2017.08.018
XIAO Zhuoyu , HE Pei , CHEN Junxu , et al. Research on variants of the design pattern detection[J]. Journal of Chinese Computer Systems, 2017, 38 (8): 1751- 1756.
doi: 10.3969/j.issn.1000-1220.2017.08.018
5 肖卓宇, 何锫, 余波, 等. 一种形式化文法关系驱动的设计模式检测方法[J]. 工程科学学报, 2016, 38 (10): 1499- 1508.
XIAO Zhuoyu , HE Pei , YU Bo , et al. An approach for design pattern detection based on the formal context-free grammar relation driver[J]. Chinese Journal of Engineering, 2016, 38 (10): 1499- 1508.
6 DWIVEDI A K , TIRKEY A , RATH S K . Applying learning-based methods for recognizing design patterns[J]. Innovations in Systems and Software Engineering, 2019, 15 (2): 87- 100.
doi: 10.1007/s11334-019-00329-3
7 MAYVAN B B , RASOOLZADEGAN A , YAZDI Z G . The state of the art on design patterns: a systematic mapping of the literature[J]. Journal of Systems and Software, 2017, 125 (3): 93- 118.
8 肖卓宇, 何锫, 余波. 一种多阶段交互式线索驱动的设计模式识别方法[J]. 北京航空航天大学学报, 2017, 43 (9): 1746- 1756.
XIAO Zhuoyu , HE Pei , YU Bo . A multi-stage approach based on interactive clues driven for design pattern identification[J]. Journal of Beijing University of Aeronautics and Astronautics, 2017, 43 (9): 1746- 1756.
9 肖卓宇, 黄海, 何锫, 等. 设计模式检测工具有效性评估策略[J]. 计算机科学与探索, 2018, 12 (3): 380- 392.
XIAO Zhuoyu , HUANG Hai , HE Pei , et al. Evaluation strategy of efficiency in design pattern detection tools[J]. Journal of Frontiers of Computer Science and Technology, 2018, 12 (3): 380- 392.
10 ZHU H , BAYLEY I . An algebra of design patterns[J]. ACM Transactions on Software Engineering and Methodology, 2013, 22 (3): 23- 61.
11 ZANONI M , FONTANA F A , STELLA F . On applying machine learning techniques for design pattern detection[J]. Journal of Systems and Software, 2015, 88 (5): 102- 117.
12 CHIHADA A , JALILI S , HASHEMINEJAD S M H , et al. Source code and design conformance, design pattern detection from source code by classification approach[J]. Applied Soft Computing, 2015, 26 (1): 357- 367.
13 FONTANA F A , MAGGIONI S , RAIBULET C . Design patterns: a survey on their micro-structures[J]. Journal of Software: Evolution and Process, 2013, 25 (1): 27- 52.
14 FONTANA F A , MAGGIONI S , RAIBULET C . Understanding the relevance of micro-structures for design patterns detection[J]. Journal of Systems and Software, 2011, 84 (12): 2334- 2347.
doi: 10.1016/j.jss.2011.07.006
15 肖卓宇, 何锫, 李港, 等. 注入间接线索的设计模式变体分类检测[J]. 小型微型计算机系统, 2018, 39 (6): 1335- 1341.
doi: 10.3969/j.issn.1000-1220.2018.06.039
XIAO Zhuoyu , HE Pei , LI Gang , et al. Injected Indirect clues for variants of design pattern detection[J]. Journal of Chinese Computer Systems, 2018, 39 (6): 1335- 1341.
doi: 10.3969/j.issn.1000-1220.2018.06.039
16 YU D , ZHANG P , YANG J , et al. Efficiently detecting structural design pattern instances based on ordered sequences[J]. Journal of Systems and Software, 2018, 91 (5): 35- 56.
17 DWIVEDI A K , TIRKEY A , RATH S K . Software design pattern mining using classification-based techniques[J]. Frontiers of Computer Science, 2018, 12 (5): 908- 922.
18 PETTERSON N , L WE W , NIVRE J . Evaluation of accuracy in design pattern occurrence detection[J]. IEEE Transactions on Software Engineering, 2010, 36 (4): 575- 590.
19 肖卓宇, 黎妍, 何锫, 等. 基于矩阵积分评估的设计模式检测研究[J]. 小型微型计算机系统, 2016, 37 (7): 1428- 1433.
XIAO Zhuoyu , LI Yan , HE Pei , et al. Research on matrix grade evaluation based on design pattern detection[J]. Journal of Chinese Computer Systems, 2016, 37 (7): 1428- 1433.
20 MAYVAN B B , RASOOLZADEGAN A . Design pattern detection based on the graph theory[J]. Knowledge-Based Systems, 2017, 120 (1): 211- 225.
21 肖卓宇, 何锫, 杨鑫维, 等. 基于文法产生式优化的设计模式识别方法[J]. 电子科技大学学报, 2017, 46 (3): 569- 576.
XIAO Zhuoyu , HE Pei , YANG Xinwei , et al. An optimization method for design pattern identification based on the grammar production[J]. Journal of University of Electronic Science and Technology of China, 2017, 46 (3): 569- 576.
22 GUÉHÉNEUC Y G. P-mart: pattern-like micro architecture repository[C]//Proceedings of the 1st EuroPLoP Focus Group on pattern repositories. Ottawa, Canada: IEEE, 2007: 1-3.
23 ERICH GAMMA , RICHARD HELM , RALPH JOHNSON , et al. Design pattern: elements of reusable object-oriented software[M]. Bombay, India: Addison Wesley, 1995: 1- 22.
24 DE LUCIA A, DEUFEMIA V, GRAVINO C, et al. Impact of design pattern implementation variants on the retrieval effectiveness of a recovery tool: an exploratory Study[C]//2018 44th Euromicro Conference on Software Engineering and Advanced Applications. Seaa, Prague: IEEE, 2018: 159-166.
25 肖卓宇, 何锫, 余波, 等. 基于FCA与CBR的设计模式检测[J]. 山东大学学报(工学版), 2016, 46 (2): 22- 28.
XIAO Zhuoyu , HE Pei , YU Bo , et al. Design patterns detection based on FCA and CBR[J]. Journal of Shandong University (Engineering Science), 2016, 46 (2): 22- 28.
26 肖卓宇, 何锫, 余波. 非标准设计模式的恢复[J]. 计算机工程与设计, 2019, 40 (1): 143- 148.
XIAO Zhuoyu , HE Pei , YU Bo . Recovery of non-standard design pattern[J]. Computer Engineering and Design, 2019, 40 (1): 143- 148.
27 肖卓宇, 何锫, 黎妍. 基于设计模式角色的附加关系检测研究[J]. 计算机应用研究, 2015, 32 (7): 2042- 2045.
XIAO Zhuoyu , HE Pei , LI Yan . Study on the additional relationships based on design pattern's roles[J]. Application Research of Computers, 2015, 32 (7): 2042- 2045.
[1] 白琳,俱通,王浩,雷明珠,潘晓英. 面向不平衡数据的提升均衡集成学习算法[J]. 山东大学学报 (工学版), 2024, 54(4): 59-66.
[2] 陈晓江,杨晓奇,陈广豪,刘伍颖. 混合BERT和宽度学习的低时间复杂度短文本分类[J]. 山东大学学报 (工学版), 2024, 54(4): 51-58.
[3] 宋辉,张轶哲,张功萱,孟元. 基于类权重和最小化预测熵的测试时集成方法[J]. 山东大学学报 (工学版), 2024, 54(3): 36-43.
[4] 聂秀山,巩蕊,董飞,郭杰,马玉玲. 短视频场景分类方法综述[J]. 山东大学学报 (工学版), 2024, 54(3): 1-11.
[5] 徐金华,罗义凯,李昱燃,李岩. 基于时频分解与深度学习的轨道客流预测[J]. 山东大学学报 (工学版), 2024, 54(2): 60-68.
[6] 马坤,刘筱云,李乐平,纪科,陈贞翔,杨波. 用于意图识别的自适应多标签信息学习模型[J]. 山东大学学报 (工学版), 2024, 54(1): 45-51.
[7] 于泓,杜娟,魏琳,张利. 计及行为特征的市场化用户电量数据拟合方法[J]. 山东大学学报 (工学版), 2023, 53(4): 113-119.
[8] 李颖,王建坤. 基于监督图正则化和信息融合的轻度认知障碍分类方法[J]. 山东大学学报 (工学版), 2023, 53(4): 65-73.
[9] 张喜龙,韩萌,陈志强,武红鑫,李慕航. 动态集成选择的不平衡漂移数据流Boosting分类算法[J]. 山东大学学报 (工学版), 2023, 53(4): 83-92.
[10] 刘财辉,周琪,叶晓文. 一种基于改进ReliefF算法的入侵检测模型[J]. 山东大学学报 (工学版), 2023, 53(2): 1-10.
[11] 孟令灿,聂秀山,张雪. 基于遮挡目标去除的公交车拥挤度分类算法[J]. 山东大学学报 (工学版), 2022, 52(4): 83-88.
[12] 孙志巍,宋明阳,潘泽华,景丽萍. 上下文感知的判别式主题模型[J]. 山东大学学报 (工学版), 2022, 52(4): 131-138.
[13] 王丽,于明仟,刘文鹏,周瑜,郑蕊蕊,贺建军. 面向类不平衡数据的K近邻偏标记学习算法[J]. 山东大学学报 (工学版), 2022, 52(3): 18-24.
[14] 龚楷伦,翟婷婷,唐鸿成. 一种面向多标签分类的在线主动学习算法[J]. 山东大学学报 (工学版), 2022, 52(2): 80-88.
[15] 张沁洋,李旭,姚春龙,李长吾. 结合句法依存信息的方面级情感分类[J]. 山东大学学报 (工学版), 2021, 51(2): 83-89.
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
[1] 王素玉,艾兴,赵军,李作丽,刘增文 . 高速立铣3Cr2Mo模具钢切削力建模及预测[J]. 山东大学学报(工学版), 2006, 36(1): 1 -5 .
[2] 张永花,王安玲,刘福平 . 低频非均匀电磁波在导电界面的反射相角[J]. 山东大学学报(工学版), 2006, 36(2): 22 -25 .
[3] 李 侃 . 嵌入式相贯线焊接控制系统开发与实现[J]. 山东大学学报(工学版), 2008, 38(4): 37 -41 .
[4] 孔祥臻,刘延俊,王勇,赵秀华 . 气动比例阀的死区补偿与仿真[J]. 山东大学学报(工学版), 2006, 36(1): 99 -102 .
[5] 来翔 . 用胞映射方法讨论一类MKdV方程[J]. 山东大学学报(工学版), 2006, 36(1): 87 -92 .
[6] 余嘉元1 , 田金亭1 , 朱强忠2 . 计算智能在心理学中的应用[J]. 山东大学学报(工学版), 2009, 39(1): 1 -5 .
[7] 陈瑞,李红伟,田靖. 磁极数对径向磁轴承承载力的影响[J]. 山东大学学报(工学版), 2018, 48(2): 81 -85 .
[8] 李可,刘常春,李同磊 . 一种改进的最大互信息医学图像配准算法[J]. 山东大学学报(工学版), 2006, 36(2): 107 -110 .
[9] 季涛,高旭,孙同景,薛永端,徐丙垠 . 铁路10 kV自闭/贯通线路故障行波特征分析[J]. 山东大学学报(工学版), 2006, 36(2): 111 -116 .
[10] 浦剑1 ,张军平1 ,黄华2 . 超分辨率算法研究综述[J]. 山东大学学报(工学版), 2009, 39(1): 27 -32 .