一、UML简介
本单元的核心内容是学习UML建模语言,通过理解UML建模语言来编写一个类解析器。
统一建模语言(英语:Unified Modeling Language,缩写 UML)是非专利的第三代建模和规约语言。UML是一种开放的方法,用于说明、可视化、构建和编写一个正在开发的、面向对象的、软件密集系统的制品的开放方法。UML展现了一系列最佳工程实践,这些最佳实践在对大规模,复杂系统进行建模方面,特别是在软件架构层次已经被验证有效。
在UML系统开发中有三个主要的模型:
功能模型:从用户的角度展示系统的功能,包括用例图。
对象模型:采用对象,属性,操作,关联等概念展示系统的结构和基础,包括类别图、对象图。
动态模型:展现系统的内部行为。包括序列图,活动图,状态图。
区分UML模型和UML图是非常重要的,UML图,包括用例图、协作图、活动图、序列图、部署图、构件图、类图、状态图,是模型中信息的图形表达方式,但是UML模型独立于UML图存在。UML的当前版本只提供了模型信息的交换,而没有提供图信息的交换。
二、代码分析
第13次作业
UML单元的第一次作业,作业的目标——类解析器的主要框架已经完成,我们所要做的工作只是实现课程组提供的官方接口,并实现其中的功能。通过分析作业需求,其实本次作业的核心就是分析UML的各种元素,构建自己的UML图模型。
架构设计
按照接口中方法的需求来有针对性的建立模型,将交互类与UML图类分离,交互类UmlInteraction的主要任务知识进行查询,而查询逻辑全部置放于UML图类,使交互类精简且易于阅读。由于官方包中UML元素的定义比较精简,所以需要建立模型整合相关元素,提高查询效率。第一次作业中查询指令都比较简单,需要注意的点是在进行图的查询时,要做好标记,避免在循环继承时出现死循环的现象。
类图
Metrics分析
Method | ev(G) | iv(G) | v(G) |
---|---|---|---|
com.homework13.Main.main(String[]) | 1 | 1 | 1 |
com.homework13.MyUmlClass.MyUmlClass(UmlClass) | 1 | 1 | 1 |
com.homework13.MyUmlClass.addAssociation(MyUmlClass) | 1 | 1 | 1 |
com.homework13.MyUmlClass.addAttribute(UmlAttribute) | 1 | 1 | 1 |
com.homework13.MyUmlClass.addInterface(MyUmlInterface) | 1 | 1 | 1 |
com.homework13.MyUmlClass.addOperation(MyUmlOperation) | 1 | 1 | 1 |
com.homework13.MyUmlClass.associationNumAdd() | 1 | 1 | 1 |
com.homework13.MyUmlClass.getAssoClassList() | 1 | 5 | 5 |
com.homework13.MyUmlClass.getAssociationNum() | 1 | 1 | 2 |
com.homework13.MyUmlClass.getAttrbuteMapSize() | 1 | 1 | 1 |
com.homework13.MyUmlClass.getAttributeVisibility(String) | 3 | 6 | 8 |
com.homework13.MyUmlClass.getClassAttributeCount(AttributeQueryType) | 2 | 2 | 3 |
com.homework13.MyUmlClass.getClassOperationCount(ArrayList |
2 | 5 | 7 |
com.homework13.MyUmlClass.getClassOperationVisibility(String) | 1 | 3 | 3 |
com.homework13.MyUmlClass.getId() | 1 | 1 | 1 |
com.homework13.MyUmlClass.getImplementInterfaceList() | 1 | 11 | 11 |
com.homework13.MyUmlClass.getInformationNotHidden() | 1 | 6 | 6 |
com.homework13.MyUmlClass.getName() | 1 | 1 | 1 |
com.homework13.MyUmlClass.getParentClass() | 1 | 1 | 1 |
com.homework13.MyUmlClass.setParentClass(MyUmlClass) | 1 | 1 | 1 |
com.homework13.MyUmlInteraction.MyUmlInteraction(UmlElement...) | 1 | 2 | 2 |
com.homework13.MyUmlInteraction.getClassAssociatedClassList(String) | 2 | 1 | 3 |
com.homework13.MyUmlInteraction.getClassAssociationCount(String) | 2 | 1 | 3 |
com.homework13.MyUmlInteraction.getClassAttributeCount(String,AttributeQueryType) | 2 | 1 | 3 |
com.homework13.MyUmlInteraction.getClassAttributeVisibility(String,String) | 3 | 1 | 5 |
com.homework13.MyUmlInteraction.getClassCount() | 1 | 1 | 1 |
com.homework13.MyUmlInteraction.getClassOperationCount(String,OperationQueryType[]) | 2 | 2 | 5 |
com.homework13.MyUmlInteraction.getClassOperationVisibility(String,String) | 2 | 1 | 3 |
com.homework13.MyUmlInteraction.getImplementInterfaceList(String) | 2 | 2 | 4 |
com.homework13.MyUmlInteraction.getInformationNotHidden(String) | 2 | 1 | 3 |
com.homework13.MyUmlInteraction.getTopParentClass(String) | 2 | 2 | 4 |
com.homework13.MyUmlInterface.MyUmlInterface(UmlInterface) | 1 | 1 | 1 |
com.homework13.MyUmlInterface.addParentInterface(MyUmlInterface) | 1 | 1 | 1 |
com.homework13.MyUmlInterface.getId() | 1 | 1 | 1 |
com.homework13.MyUmlInterface.getName() | 1 | 1 | 1 |
com.homework13.MyUmlInterface.getParentList() | 1 | 1 | 1 |
com.homework13.MyUmlOperation.MyUmlOperation(UmlOperation) | 1 | 1 | 1 |
com.homework13.MyUmlOperation.addParameter(UmlParameter) | 1 | 1 | 5 |
com.homework13.MyUmlOperation.getId() | 1 | 1 | 1 |
com.homework13.MyUmlOperation.getName() | 1 | 1 | 1 |
com.homework13.MyUmlOperation.getParentId() | 1 | 1 | 1 |
com.homework13.MyUmlOperation.getVisibility() | 1 | 1 | 1 |
com.homework13.MyUmlOperation.isMatchType(ArrayList |
3 | 2 | 8 |
com.homework13.UmlGraph.UmlGraph(ArrayList |
5 | 10 | 22 |
com.homework13.UmlGraph.getClassCount() | 1 | 1 | 1 |
com.homework13.UmlGraph.getInterfaceName(String) | 1 | 1 | 1 |
com.homework13.UmlGraph.getUmlClass(String) | 3 | 2 | 5 |
Class | OCavg | WMC | |
com.homework13.Main | 1 | 1 | |
com.homework13.MyUmlClass | 2.79 | 53 | |
com.homework13.MyUmlInteraction | 2.27 | 25 | |
com.homework13.MyUmlInterface | 1 | 5 | |
com.homework13.MyUmlOperation | 2.29 | 16 | |
com.homework13.UmlGraph | 7 | 28 | |
Package | v(G)avg | v(G)tot | |
com.homework13 | 3.09 | 145 | |
Module | v(G)avg | v(G)tot | |
OOtask4 | 3.09 | 145 | |
Project | v(G)avg | v(G)tot | |
project | 3.09 | 145 |
第14次作业
UML单元的第二次作业,对比上次需求,主要是增加了对顺序图和状态图的解析任务。
架构设计
本次作业和上次作业的设计基本类似,根据需要设计模型和查询方法。对于状态图的设计,可以建立一个具体的状态类,整合三类状态(初态、中间态、终态),来构建状态转移网,这样的设计能够方便查询,具体代码也容易读懂。
类图
Metrics分析
Method | ev(G) | iv(G) | v(G) |
---|---|---|---|
com.homework14.Main.main(String[]) | 1 | 1 | 1 |
com.homework14.MyUmlClass.MyUmlClass(UmlClass) | 1 | 1 | 1 |
com.homework14.MyUmlClass.addAssociation(MyUmlClass) | 1 | 1 | 1 |
com.homework14.MyUmlClass.addAttribute(UmlAttribute) | 1 | 1 | 1 |
com.homework14.MyUmlClass.addInterface(MyUmlInterface) | 1 | 1 | 1 |
com.homework14.MyUmlClass.addOperation(MyUmlOperation) | 1 | 1 | 1 |
com.homework14.MyUmlClass.associationNumAdd() | 1 | 1 | 1 |
com.homework14.MyUmlClass.getAssoClassList() | 1 | 5 | 5 |
com.homework14.MyUmlClass.getAssociationNum() | 1 | 1 | 2 |
com.homework14.MyUmlClass.getAttrbuteMapSize() | 1 | 1 | 1 |
com.homework14.MyUmlClass.getAttributeVisibility(String) | 3 | 6 | 8 |
com.homework14.MyUmlClass.getClassAttributeCount(AttributeQueryType) | 2 | 2 | 3 |
com.homework14.MyUmlClass.getClassOperationCount(ArrayList |
2 | 5 | 7 |
com.homework14.MyUmlClass.getClassOperationVisibility(String) | 1 | 3 | 3 |
com.homework14.MyUmlClass.getId() | 1 | 1 | 1 |
com.homework14.MyUmlClass.getImplementInterfaceList() | 1 | 11 | 11 |
com.homework14.MyUmlClass.getInformationNotHidden() | 1 | 6 | 6 |
com.homework14.MyUmlClass.getName() | 1 | 1 | 1 |
com.homework14.MyUmlClass.getParentClass() | 1 | 1 | 1 |
com.homework14.MyUmlClass.setParentClass(MyUmlClass) | 1 | 1 | 1 |
com.homework14.MyUmlGeneralInteraction.MyUmlGeneralInteraction(UmlElement...) | 1 | 2 | 2 |
com.homework14.MyUmlGeneralInteraction.getClassAssociatedClassList(String) | 2 | 1 | 3 |
com.homework14.MyUmlGeneralInteraction.getClassAssociationCount(String) | 2 | 1 | 3 |
com.homework14.MyUmlGeneralInteraction.getClassAttributeCount(String,AttributeQueryType) | 2 | 1 | 3 |
com.homework14.MyUmlGeneralInteraction.getClassAttributeVisibility(String,String) | 3 | 1 | 5 |
com.homework14.MyUmlGeneralInteraction.getClassCount() | 1 | 1 | 1 |
com.homework14.MyUmlGeneralInteraction.getClassOperationCount(String,OperationQueryType[]) | 2 | 2 | 5 |
com.homework14.MyUmlGeneralInteraction.getClassOperationVisibility(String,String) | 2 | 1 | 3 |
com.homework14.MyUmlGeneralInteraction.getImplementInterfaceList(String) | 2 | 2 | 4 |
com.homework14.MyUmlGeneralInteraction.getIncomingMessageCount(String,String) | 3 | 1 | 5 |
com.homework14.MyUmlGeneralInteraction.getInformationNotHidden(String) | 2 | 1 | 3 |
com.homework14.MyUmlGeneralInteraction.getMessageCount(String) | 2 | 1 | 3 |
com.homework14.MyUmlGeneralInteraction.getParticipantCount(String) | 2 | 1 | 3 |
com.homework14.MyUmlGeneralInteraction.getStateCount(String) | 2 | 1 | 3 |
com.homework14.MyUmlGeneralInteraction.getSubsequentStateCount(String,String) | 3 | 1 | 5 |
com.homework14.MyUmlGeneralInteraction.getTopParentClass(String) | 2 | 2 | 4 |
com.homework14.MyUmlGeneralInteraction.getTransitionCount(String) | 2 | 1 | 3 |
com.homework14.MyUmlInterface.MyUmlInterface(UmlInterface) | 1 | 1 | 1 |
com.homework14.MyUmlInterface.addParentInterface(MyUmlInterface) | 1 | 1 | 1 |
com.homework14.MyUmlInterface.getId() | 1 | 1 | 1 |
com.homework14.MyUmlInterface.getName() | 1 | 1 | 1 |
com.homework14.MyUmlInterface.getParentList() | 1 | 1 | 1 |
com.homework14.MyUmlLifeLine.MyUmlLifeLine(UmlLifeline) | 1 | 1 | 1 |
com.homework14.MyUmlLifeLine.addInComingNum() | 1 | 1 | 1 |
com.homework14.MyUmlLifeLine.getId() | 1 | 1 | 1 |
com.homework14.MyUmlLifeLine.getInComingNum() | 1 | 1 | 1 |
com.homework14.MyUmlLifeLine.getName() | 1 | 1 | 1 |
com.homework14.MyUmlOperation.MyUmlOperation(UmlOperation) | 1 | 1 | 1 |
com.homework14.MyUmlOperation.addParameter(UmlParameter) | 1 | 1 | 5 |
com.homework14.MyUmlOperation.getId() | 1 | 1 | 1 |
com.homework14.MyUmlOperation.getName() | 1 | 1 | 1 |
com.homework14.MyUmlOperation.getParentId() | 1 | 1 | 1 |
com.homework14.MyUmlOperation.getVisibility() | 1 | 1 | 1 |
com.homework14.MyUmlOperation.isMatchType(ArrayList |
3 | 2 | 8 |
com.homework14.MyUmlState.MyUmlState(UmlElement) | 2 | 2 | 5 |
com.homework14.MyUmlState.addState(MyUmlState) | 2 | 1 | 3 |
com.homework14.MyUmlState.equals(MyUmlState) | 1 | 1 | 1 |
com.homework14.MyUmlState.getId() | 1 | 1 | 1 |
com.homework14.MyUmlState.getName() | 1 | 1 | 1 |
com.homework14.MyUmlState.getSubsequentStateCount() | 1 | 5 | 8 |
com.homework14.UmlGraph.UmlGraph(ArrayList |
5 | 18 | 47 |
com.homework14.UmlGraph.getClassCount() | 1 | 1 | 1 |
com.homework14.UmlGraph.getInterfaceName(String) | 1 | 1 | 1 |
com.homework14.UmlGraph.getUmlClass(String) | 3 | 2 | 5 |
com.homework14.UmlGraph.getUmlInteraction(String) | 3 | 2 | 5 |
com.homework14.UmlGraph.getUmlStateMachine(String) | 3 | 2 | 5 |
com.homework14.UmlSequenceGraph.UmlSequenceGraph(UmlInteraction) | 1 | 1 | 1 |
com.homework14.UmlSequenceGraph.addLifeLine(MyUmlLifeLine) | 1 | 1 | 1 |
com.homework14.UmlSequenceGraph.addMessage(UmlMessage) | 1 | 1 | 1 |
com.homework14.UmlSequenceGraph.getId() | 1 | 1 | 1 |
com.homework14.UmlSequenceGraph.getIncomingMessageCount(String) | 3 | 4 | 5 |
com.homework14.UmlSequenceGraph.getMessageCount() | 1 | 1 | 1 |
com.homework14.UmlSequenceGraph.getName() | 1 | 1 | 1 |
com.homework14.UmlSequenceGraph.getParticipantCount() | 1 | 1 | 1 |
com.homework14.UmlSequenceGraph.init() | 1 | 3 | 3 |
com.homework14.UmlStateGraph.UmlStateGraph(UmlStateMachine) | 1 | 1 | 1 |
com.homework14.UmlStateGraph.addState(MyUmlState) | 1 | 1 | 1 |
com.homework14.UmlStateGraph.addTransition(UmlTransition) | 1 | 1 | 1 |
com.homework14.UmlStateGraph.getName() | 1 | 1 | 1 |
com.homework14.UmlStateGraph.getStateCount() | 1 | 1 | 1 |
com.homework14.UmlStateGraph.getSubsequentStateCount(String) | 5 | 4 | 6 |
com.homework14.UmlStateGraph.getTransitionCount() | 1 | 1 | 1 |
com.homework14.UmlStateGraph.init() | 3 | 3 | 4 |
com.homework14.UmlStateGraph.setFinalState(UmlFinalState) | 1 | 1 | 1 |
com.homework14.UmlStateGraph.setPseudostate(UmlPseudostate) | 1 | 1 | 1 |
com.homework14.UmlStateGraph.setRegion(UmlRegion) | 1 | 1 | 1 |
Class | OCavg | WMC | |
com.homework14.Main | 1 | 1 | |
com.homework14.MyUmlClass | 2.79 | 53 | |
com.homework14.MyUmlGeneralInteraction | 2.29 | 39 | |
com.homework14.MyUmlInterface | 1 | 5 | |
com.homework14.MyUmlLifeLine | 1 | 5 | |
com.homework14.MyUmlOperation | 2.29 | 16 | |
com.homework14.MyUmlState | 3.17 | 19 | |
com.homework14.UmlGraph | 10.5 | 63 | |
com.homework14.UmlSequenceGraph | 1.67 | 15 | |
com.homework14.UmlStateGraph | 1.73 | 19 | |
Package | v(G)avg | v(G)tot | |
com.homework14 | 3.02 | 260 | |
Module | v(G)avg | v(G)tot | |
OOtask4 | 3.02 | 260 | |
Project | v(G)avg | v(G)tot | |
project | 3.02 | 260 |
第15次作业
本次作业是UML单元的最后一次作业,在这一单元,需求的迭代十分清晰,最后一次作业需要对我们构建的模型进行有效性检查。
架构设计
本次作业并不需要新建或是修改之前的模型,新增的检查部分事实上还是属于一种只发生一次的查询行为,最终还是可以将问题转换为图的遍历。
类图
Metrics分析
Method | ev(G) | iv(G) | v(G) |
---|---|---|---|
com.homework15.Main.main(String[]) | 1 | 1 | 1 |
com.homework15.MyUmlClass.MyUmlClass(UmlClass) | 1 | 1 | 1 |
com.homework15.MyUmlClass.addAssociation(MyUmlClass) | 1 | 1 | 1 |
com.homework15.MyUmlClass.addAttribute(UmlAttribute) | 1 | 1 | 1 |
com.homework15.MyUmlClass.addEnd(UmlAssociationEnd) | 1 | 1 | 1 |
com.homework15.MyUmlClass.addInterface(MyUmlInterface) | 1 | 1 | 1 |
com.homework15.MyUmlClass.addOperation(MyUmlOperation) | 1 | 1 | 1 |
com.homework15.MyUmlClass.associationNumAdd() | 1 | 1 | 1 |
com.homework15.MyUmlClass.bfs(MyUmlInterface) | 1 | 4 | 4 |
com.homework15.MyUmlClass.equals(Object) | 2 | 1 | 3 |
com.homework15.MyUmlClass.getAssoClassList() | 1 | 5 | 5 |
com.homework15.MyUmlClass.getAssociationNum() | 1 | 1 | 2 |
com.homework15.MyUmlClass.getAttrbuteMapSize() | 1 | 1 | 1 |
com.homework15.MyUmlClass.getAttributeVisibility(String) | 3 | 6 | 8 |
com.homework15.MyUmlClass.getClassAttributeCount(AttributeQueryType) | 2 | 2 | 3 |
com.homework15.MyUmlClass.getClassOperationCount(ArrayList |
2 | 5 | 7 |
com.homework15.MyUmlClass.getClassOperationVisibility(String) | 1 | 3 | 3 |
com.homework15.MyUmlClass.getDuplicatedNameSet() | 1 | 9 | 9 |
com.homework15.MyUmlClass.getId() | 1 | 1 | 1 |
com.homework15.MyUmlClass.getImplementInterfaceList() | 3 | 11 | 12 |
com.homework15.MyUmlClass.getInformationNotHidden() | 1 | 6 | 6 |
com.homework15.MyUmlClass.getInside() | 1 | 1 | 1 |
com.homework15.MyUmlClass.getName() | 1 | 1 | 1 |
com.homework15.MyUmlClass.getParentClass() | 1 | 1 | 1 |
com.homework15.MyUmlClass.hashCode() | 1 | 1 | 1 |
com.homework15.MyUmlClass.isRepeat() | 1 | 2 | 2 |
com.homework15.MyUmlClass.isRepeatIR() | 8 | 6 | 8 |
com.homework15.MyUmlClass.setParentClass(MyUmlClass) | 1 | 1 | 1 |
com.homework15.MyUmlClass.toString() | 1 | 1 | 1 |
com.homework15.MyUmlGeneralInteraction.MyUmlGeneralInteraction(UmlElement...) | 1 | 2 | 2 |
com.homework15.MyUmlGeneralInteraction.checkForUml001() | 2 | 1 | 2 |
com.homework15.MyUmlGeneralInteraction.checkForUml002() | 2 | 1 | 2 |
com.homework15.MyUmlGeneralInteraction.checkForUml003() | 2 | 1 | 2 |
com.homework15.MyUmlGeneralInteraction.checkForUml004() | 2 | 1 | 2 |
com.homework15.MyUmlGeneralInteraction.checkForUml005() | 7 | 4 | 14 |
com.homework15.MyUmlGeneralInteraction.checkForUml006() | 2 | 1 | 2 |
com.homework15.MyUmlGeneralInteraction.checkForUml007() | 2 | 1 | 2 |
com.homework15.MyUmlGeneralInteraction.checkForUml008() | 2 | 1 | 2 |
com.homework15.MyUmlGeneralInteraction.getClassAssociatedClassList(String) | 2 | 1 | 3 |
com.homework15.MyUmlGeneralInteraction.getClassAssociationCount(String) | 2 | 1 | 3 |
com.homework15.MyUmlGeneralInteraction.getClassAttributeCount(String,AttributeQueryType) | 2 | 1 | 3 |
com.homework15.MyUmlGeneralInteraction.getClassAttributeVisibility(String,String) | 3 | 1 | 5 |
com.homework15.MyUmlGeneralInteraction.getClassCount() | 1 | 1 | 1 |
com.homework15.MyUmlGeneralInteraction.getClassOperationCount(String,OperationQueryType[]) | 2 | 2 | 5 |
com.homework15.MyUmlGeneralInteraction.getClassOperationVisibility(String,String) | 2 | 1 | 3 |
com.homework15.MyUmlGeneralInteraction.getImplementInterfaceList(String) | 2 | 2 | 4 |
com.homework15.MyUmlGeneralInteraction.getIncomingMessageCount(String,String) | 3 | 1 | 5 |
com.homework15.MyUmlGeneralInteraction.getInformationNotHidden(String) | 2 | 1 | 3 |
com.homework15.MyUmlGeneralInteraction.getMessageCount(String) | 2 | 1 | 3 |
com.homework15.MyUmlGeneralInteraction.getParticipantCount(String) | 2 | 1 | 3 |
com.homework15.MyUmlGeneralInteraction.getStateCount(String) | 2 | 1 | 3 |
com.homework15.MyUmlGeneralInteraction.getSubsequentStateCount(String,String) | 3 | 1 | 5 |
com.homework15.MyUmlGeneralInteraction.getTopParentClass(String) | 2 | 2 | 4 |
com.homework15.MyUmlGeneralInteraction.getTransitionCount(String) | 2 | 1 | 3 |
com.homework15.MyUmlInterface.MyUmlInterface(UmlInterface) | 1 | 1 | 1 |
com.homework15.MyUmlInterface.addAttribute(UmlAttribute) | 1 | 1 | 1 |
com.homework15.MyUmlInterface.addParentInterface(MyUmlInterface) | 1 | 1 | 1 |
com.homework15.MyUmlInterface.equals(Object) | 2 | 1 | 3 |
com.homework15.MyUmlInterface.getBfsPath() | 1 | 5 | 5 |
com.homework15.MyUmlInterface.getId() | 1 | 1 | 1 |
com.homework15.MyUmlInterface.getInside() | 1 | 1 | 1 |
com.homework15.MyUmlInterface.getName() | 1 | 1 | 1 |
com.homework15.MyUmlInterface.getParentList() | 1 | 1 | 1 |
com.homework15.MyUmlInterface.getUnVisited(ArrayList |
5 | 4 | 6 |
com.homework15.MyUmlInterface.hashCode() | 1 | 1 | 1 |
com.homework15.MyUmlInterface.isAllAttrbutePublic() | 3 | 2 | 3 |
com.homework15.MyUmlInterface.isVisited() | 1 | 1 | 1 |
com.homework15.MyUmlInterface.unVisit() | 1 | 1 | 1 |
com.homework15.MyUmlInterface.visit() | 1 | 1 | 1 |
com.homework15.MyUmlLifeLine.MyUmlLifeLine(UmlLifeline) | 1 | 1 | 1 |
com.homework15.MyUmlLifeLine.addInComingNum() | 1 | 1 | 1 |
com.homework15.MyUmlLifeLine.getId() | 1 | 1 | 1 |
com.homework15.MyUmlLifeLine.getInComingNum() | 1 | 1 | 1 |
com.homework15.MyUmlLifeLine.getName() | 1 | 1 | 1 |
com.homework15.MyUmlOperation.MyUmlOperation(UmlOperation) | 1 | 1 | 1 |
com.homework15.MyUmlOperation.addParameter(UmlParameter) | 1 | 1 | 5 |
com.homework15.MyUmlOperation.getId() | 1 | 1 | 1 |
com.homework15.MyUmlOperation.getName() | 1 | 1 | 1 |
com.homework15.MyUmlOperation.getParentId() | 1 | 1 | 1 |
com.homework15.MyUmlOperation.getVisibility() | 1 | 1 | 1 |
com.homework15.MyUmlOperation.isMatchType(ArrayList |
3 | 2 | 8 |
com.homework15.MyUmlState.MyUmlState(UmlElement) | 2 | 2 | 5 |
com.homework15.MyUmlState.addState(MyUmlState) | 2 | 1 | 3 |
com.homework15.MyUmlState.equals(MyUmlState) | 1 | 1 | 1 |
com.homework15.MyUmlState.getId() | 1 | 1 | 1 |
com.homework15.MyUmlState.getName() | 1 | 1 | 1 |
com.homework15.MyUmlState.getSubsequentStateCount() | 1 | 5 | 8 |
com.homework15.UmlGraph.UmlGraph(ArrayList |
5 | 19 | 48 |
com.homework15.UmlGraph.dfs(MyUmlInterface,MyUmlInterface,HashSet |
2 | 3 | 4 |
com.homework15.UmlGraph.getCircle() | 8 | 8 | 10 |
com.homework15.UmlGraph.getCircleInterfaces(MyUmlInterface) | 1 | 2 | 2 |
com.homework15.UmlGraph.getClassCount() | 1 | 1 | 1 |
com.homework15.UmlGraph.getDuplicateNameSet() | 1 | 2 | 2 |
com.homework15.UmlGraph.getInterfaceName(String) | 1 | 1 | 1 |
com.homework15.UmlGraph.getRepeat() | 3 | 7 | 7 |
com.homework15.UmlGraph.getRepeatIrClass() | 1 | 3 | 3 |
com.homework15.UmlGraph.getUmlClass(String) | 3 | 2 | 5 |
com.homework15.UmlGraph.getUmlInteraction(String) | 3 | 2 | 5 |
com.homework15.UmlGraph.getUmlStateMachine(String) | 3 | 2 | 5 |
com.homework15.UmlGraph.haveOutgoingState() | 2 | 2 | 3 |
com.homework15.UmlGraph.haveSeveralInitOutState() | 2 | 2 | 3 |
com.homework15.UmlGraph.isAllInterfacePublic() | 1 | 2 | 2 |
com.homework15.UmlGraph.isRepeat(MyUmlInterface) | 3 | 4 | 5 |
com.homework15.UmlSequenceGraph.UmlSequenceGraph(UmlInteraction) | 1 | 1 | 1 |
com.homework15.UmlSequenceGraph.addLifeLine(MyUmlLifeLine) | 1 | 1 | 1 |
com.homework15.UmlSequenceGraph.addMessage(UmlMessage) | 1 | 1 | 1 |
com.homework15.UmlSequenceGraph.getId() | 1 | 1 | 1 |
com.homework15.UmlSequenceGraph.getIncomingMessageCount(String) | 3 | 4 | 5 |
com.homework15.UmlSequenceGraph.getMessageCount() | 1 | 1 | 1 |
com.homework15.UmlSequenceGraph.getName() | 1 | 1 | 1 |
com.homework15.UmlSequenceGraph.getParticipantCount() | 1 | 1 | 1 |
com.homework15.UmlSequenceGraph.init() | 1 | 3 | 3 |
com.homework15.UmlStateGraph.UmlStateGraph(UmlStateMachine) | 1 | 1 | 1 |
com.homework15.UmlStateGraph.addState(MyUmlState) | 1 | 1 | 1 |
com.homework15.UmlStateGraph.addTransition(UmlTransition) | 1 | 1 | 1 |
com.homework15.UmlStateGraph.getName() | 1 | 1 | 1 |
com.homework15.UmlStateGraph.getStateCount() | 1 | 1 | 1 |
com.homework15.UmlStateGraph.getSubsequentStateCount(String) | 5 | 4 | 6 |
com.homework15.UmlStateGraph.getTransitionCount() | 1 | 1 | 1 |
com.homework15.UmlStateGraph.haveOutgoingState() | 3 | 3 | 4 |
com.homework15.UmlStateGraph.haveSeveralInitOutState() | 1 | 3 | 4 |
com.homework15.UmlStateGraph.init() | 3 | 3 | 4 |
com.homework15.UmlStateGraph.setFinalState(UmlFinalState) | 1 | 1 | 1 |
com.homework15.UmlStateGraph.setPseudostate(UmlPseudostate) | 1 | 1 | 1 |
com.homework15.UmlStateGraph.setRegion(UmlRegion) | 1 | 1 | 1 |
Class | OCavg | WMC | |
com.homework15.Main | 1 | 1 | |
com.homework15.MyUmlClass | 2.93 | 82 | |
com.homework15.MyUmlGeneralInteraction | 2.4 | 60 | |
com.homework15.MyUmlInterface | 1.8 | 27 | |
com.homework15.MyUmlLifeLine | 1 | 5 | |
com.homework15.MyUmlOperation | 2.29 | 16 | |
com.homework15.MyUmlState | 3.17 | 19 | |
com.homework15.UmlGraph | 6.56 | 105 | |
com.homework15.UmlSequenceGraph | 1.67 | 15 | |
com.homework15 .UmlStateGraph | 1.92 | 25 | |
Package | v(G)avg | v(G)tot | |
com.homework15 | 3.14 | 392 | |
Module | v(G)avg | v(G)tot | |
OOtask4 | 3.14 | 392 | |
Project | v(G)avg | v(G)tot | |
project | 3.14 | 392 |
总结
事实上,总结这三次作业的共性,我认为UML语言成为了一个载体,而核心目标是在考验我们分析需求,构建模型的能力,这一点在第三单元的JML训练中也有体现。在本单元作业中,课程组提供了基本的框架与UML元素体系,我要做的则是对这些独立的元素进行包装,就比如说第一次作业中主要针对对类图的查询,而类图中主要查询的都是类、接口这些元素,显然原生元素是不能够满足查询需求的,因而选择UmlClass和UmlInterface两个类进行包装,添加查询时需要的各种属性和元素,最后构建一个完整的类图类来包装我们自定义的元素和查询逻辑。后续的作业也能够采用这种逻辑来进行代码的设计和实现。
三、OO课程总结
一个学期的OO课程马上完结,回顾这一个学期的内容,课程组为我们准备了四个单元作业,并辅以实验课和研讨课来进行提高,一个学期的OO课程,每周都要面对的一次需求实现,完成这些作业绝不轻松,但是经过一个学期的锻炼和提高,我的收获也有很多。下面从几个方面来说一说我的收获。
1、架构设计与对面向对象方法的理解
从最初的拿到指导书就开始写代码,到后面先过几遍指导书和讨论区,虽然各个单元的核心内容并不相同,但是经过了前几次作业中比较痛苦的重构过程,我也认识到了一个良好、可扩展的代码架构对于后续作业迭代的重要性。
第二单元的核心是多线程工具的使用,课程组以电梯为载体来进行多线程的教学。由于之前没有接触过多线程编程,拿到第一次电梯作业时,我犹豫了很长一段时间,一是不知道从什么地方入手,二是对多线程工具不太熟练,因此 我花了大量时间来进行尝试,但最终总算是有惊无险地通过了测试。说到多线程这一单元的收获,我觉得最重要的就是学会了多线程工具的使用,形成了一套自己的多线程程序调试方法。在面向对象的学习中,我觉得架构设计、功能的分离、抽象才是最重要的一部分,而使用的算法、最终对程序的优化的优先级要低一些,在形成成熟的框架之后,相应的算法、优化部分只需要填空即可。在这一单元的设计中,我的架构几乎没有动过,在算法方面也一直采用LOOK算法进行电梯的调度,仍然取得了不错的成绩,我认为这也是架构重要性的一个佐证。
第三单元是JML单元,主要任务是在给定的JML规范下填补相应的代码,这一单元的难度在我看来要比前几个单元小不少,一是模型的构建比较简单,二是代码结构已经由课程组给出,我们只需要进行相关函数的实现。这一单元的架构设计比较随意,只需要构造出相关的容器来存储JML规格中需要的信息即可。
第四单元与第三单元较为类似,核心是UML图的学习,但是我认为这一单元最重要的是学习通过面向对象这种思想来构建模型,这一单元的也是需要我们构建模型并填补函数,但是这一单元的模型相比第三单元更加复杂,更能体现出面向对象的特点。三四单元的共同特点就是多次作业之间的迭代特征明显,实现需求时并不需要修改已经成型的代码,只需要在之前代码的基础上进行增量更新,这种增量更新的方式是更加合理、更加符合现实场景的,同时,我也认为课程组通过这种方式减小了我们因代码架构不合理而进行重构的可能。
2、测试与实践的演进
测试作为程序设计中的重要环节,在OO课程的体现上也十分明显,主要体现在每次的DEBUG环节和互测环节中。怎样通过构造数据来检测程序中存在的问题,事实上,我在这一方面做的还有些不足,在数据的构造方面,我更习惯于手动构造数据,在互测环节,我也更多的采用了阅读代码定点爆破的方法,对自动化评测的探索较少,在研讨课上看到了很多大佬自己搭建评测机的例子,自己却没有进行尝试,这也是我在课程上偷懒的一种表现。但是通过一个学期的互测体验,我也形成了一套自己的定点爆破策略,也收到了比较好的效果。这套方法的主要思想还是在于构造边界数据和特殊数据来进行hack,最主要的工作是阅读同学的代码。比如在第一单元,构造可化简的表达式,多重括号嵌套有可能导致爆栈的表达式来hack,在第二单元,构造多组大量换乘请求,在第三单元构造较特殊的图来进行hack。都取得了不错的hack效果。虽然这种强行构造特殊边界值的方法能够hack一部分数据,但不能构造出大量随机数据来充分检验程序在一般情况下的正确性,所以要实现更好的测试效果,还是需要自动化的方法,构建随机数据生成器和评测机来进行hack,既能减少自己的时间花费,也能够通过构建评测机提高自己的能力,尽管OO课程已经要结束了,但在这方面的功课,我还需要在后面去花时间做。
3、课程收获
谈到收获,我认为这也正是OO课程虽然折磨了我很长时间,但我仍然很喜欢这门课的原因,虽然为了完成每周一次的作业,需要花费大量时间,熬很多夜,掉不少头发,但是通过这门课程获得的知识和技巧确实实在的,回顾这一个学期的OO课程,我会发现在完成了课程组的任务之后,我的努力都是有回报的,看到测试结果中一列绿色的AC,我是喜悦和满足的。
总结四个单元的收获,我认为面向对象的设计思想是这些收获中最重要的,通过这一个学期的练习,我能够熟练地使用JAVA这门面向对象的语言进行编程,能够通过面向对象的思想解决生活中的一个个问题,这便是完成课程要求的一种表现。但如果这门课程的收获只有这些的话,我只能说这门课程达到了设立这门课程的基本要求,让我感到高兴的是课程目标之外的一些收获。比如在阅读互测代码时学习到了更优秀的架构,并将这种架构的优点借鉴到了自己的架构中,比如在完成作业的过程中学习到了新的算法,第二单元的LOOK、SATF,第三单元的并查集、tarjan,堆优化的dijkstra,虽然这些可能都是大佬很早前就掌握的知识,但当我第一次学习并实现这些新知识时、内心的喜悦也是无以言表的。
最后,我想再一次说一说我对面向对象这种思想的理解,OO的特点是封装、继承、多态,而这三个特点正是OO课程的核心内容,分析问题、抽象问题逻辑、构建描述问题的合理模型、实例化这种面向对象的模型来解决问题,这是我在这四单元作业中得到的一套使用面向对象思想来解决问题的方法模板。而抽象出问题逻辑和构建模型正是这套方法模板中最重要的一环,第一单元的表达式、项、因子层次,第二单元总调度器、分调度器、单个电梯的层次,第三单元关系网络、群组、单个人的层次,第四单元交互器、类图、UML元素的层次,四个单元分别构建不同的模型,抽象出最基本的元素,从最基本的元素开始开始,逐步形成不同的层次结构,最终变成问题模型,形成一个合理、完整的架构来解决问题,这是我学习OO之后最大的感受,也是我对面向对象的一种理解。
4、 改进意见
之前在知乎上看到很多对改革前北航OO课程的吐槽与批评,现在到我真正体验了这门课程,从之前学长们的评价到我的评价,感受到课改前后这门课程的巨大变化,我觉得现在的OO课程能够称得上是计算机学院的一门优秀的专业课程,但是经过一个学期学习,我认为这门课程仍然有变得更好的空间,以下是我的几点建议:
1.没有反馈的努力容易被遗忘,看不到结果的付出不会让人产生继续努力的想法,我认为实验课的结果可以提前进行公开,一是能够提高同学们参与实验课的积极性,二是能够通过及时反馈来发现自己在实验中出现的问题。
2.实验课内容可以进行一些调整,就比如本学期UML单元的两次实验,可以将最后一次填空实验进行改进,对实验内容的描述也可以更加准确,而像JML单元的JAVA内存回收实验,我认为就是一个很好的实验样板,虽然这次实验仍然有一些描述上的不全面之处,但这样的实验既能够训练我们阅读代码的能力,也能够获得一些课上学不到的知识,这样优质的实验可以更多一些。
3.JML单元的工具链虽然能够使用,但是毕竟年代久远,相应的配置和使用体验并不是很好,虽然JML单元的规格化设计和实现很有学习的必要,但相应的工具链确实不能成为这一单元课程内容的加分项,可以考虑对这部分内容进行改进。
四、对线上OO课程的感想与体会
因为疫情原因,这届OO课程只能在线上进行,相比线下的教学,线上教学让这门课程变得更加灵活,同学可以自主选择学习时间,对于网课内容的学习也可以进行多次,线上讨论课的参与度显然也要更高。但令人遗憾的是没有能和老师、助教面对面交流的机会。总而言之,从寒假的PRE实验开始的OO课程到今天也马上就要落下帷幕,下周一的典礼应该也会是最后一次OO课,一学期以来,我能够感受到各位老师和助教对OO课程的辛勤付出,感谢老师和助教们的付出,也希望这门面向对象设计与构造课程能够在未来变得越来越好。