本节和大家学习一下如何Visio画UML用例图,UML用例图主要用来图示化系统的主事件流程,它主要用来描述客户的需求,即用户希望系统具备的完成一定功能的动作。 UML用例图简介 首先看一下......
2021-06-25 865 Visio,画,UML,用例,图,只需,八步,轻松,实现,本节,
今天尝试使用visio画了一个序列图。
话不多说,先打开visio,新建一个UML序列。
先新建几个对象生命线
加入几个激活
而后是消息,实线表示请求,虚线表示响应。
当然如果不影响理解,可以不用每个请求都配上一个响应。
此UML例子是在《UML精粹:标准对象建模语言简明指南》中拿过来的,为了更好的理解这个UML,下面使用java来实现此UML。
procuct
packagecom.simon.uml.sequenceDiagram;
/**
*CreatedbyIntelliJIDEA.
*
*@author:Simon
*@date:2019-05-09
*@time:14:50
*@description:产品
*/
publicclassProduct{
privateStringname;
privatedoubleprice;
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicdoublegetPrice(){
returnprice;
}
publicdoublegetPrice(intnumber){
doubleorderLinePrice=price*number;
System.out.println("productname:"+getName()
+"\tprice:"+getPrice()
+"\tnumber:"+number
+"\torderlineprice:"+orderLinePrice
);
returnorderLinePrice;
}
publicvoidsetPrice(doubleprice){
this.price=price;
}
}
customer
packagecom.simon.uml.sequenceDiagram;
/**
*CreatedbyIntelliJIDEA.
*
*@author:Simon
*@date:2019-05-09
*@time:14:51
*@description:客户
*/
publicclassCustomer{
privatedoublediscount;
publicdoublegetDiscountedValue(Orderorder){
returndiscount*order.getBaseValue();
}
publicdoublegetDiscount(){
returndiscount;
}
publicvoidsetDiscount(doublediscount){
this.discount=discount;
}
}
order
packagecom.simon.uml.sequenceDiagram;
importjava.util.List;
/**
*CreatedbyIntelliJIDEA.
*
*@author:Simon
*@date:2019-05-09
*@time:14:50
*@description:订单
*/
publicclassOrder{
privatedoublebaseValue;
privateCustomercustomer;
privateList<OrderLine>orderLineList;
publicdoublecalculatePrice(){
doublesumOrderLinePrice=0;
for(OrderLineorderLine:orderLineList){
doubleorderLinePrice=orderLine.calculatePrice();
sumOrderLinePrice+=orderLinePrice;
}
this.setBaseValue(sumOrderLinePrice);
System.out.println("orderbaseprice:"+sumOrderLinePrice);
doublediscountedValue=getCustomer().getDiscountedValue(this);
System.out.println("orderdiscountedprice:"+discountedValue);
returndiscountedValue;
}
publicdoublegetBaseValue(){
returnbaseValue;
}
publicvoidsetBaseValue(doublebaseValue){
this.baseValue=baseValue;
}
publicList<OrderLine>getOrderLineList(){
returnorderLineList;
}
publicvoidsetOrderLineList(List<OrderLine>orderLineList){
this.orderLineList=orderLineList;
}
publicCustomergetCustomer(){
returncustomer;
}
publicvoidsetCustomer(Customercustomer){
this.customer=customer;
}
}
orderline
packagecom.simon.uml.sequenceDiagram;
/**
*CreatedbyIntelliJIDEA.
*
*@author:Simon
*@date:2019-05-09
*@time:14:50
*@description:订单明细
*/
publicclassOrderLine{
privateintnumber;
privateProductproduct;
publicOrderLine(intnumber,Productproduct){
this.number=number;
this.product=product;
}
publicdoublecalculatePrice(){
returnproduct.getPrice(number);
}
publicintgetNumber(){
returnnumber;
}
publicvoidsetNumber(intnumber){
this.number=number;
}
publicProductgetProduct(){
returnproduct;
}
publicvoidsetProduct(Productproduct){
this.product=product;
}
}
order的测试用例
packagecom.simon.uml.sequenceDiagram;
importorg.junit.Assert;
importjava.util.ArrayList;
importjava.util.List;
/**
*CreatedbyIntelliJIDEA.
*
*@author:Simon
*@date:2019-05-09
*@time:15:23
*@description:
*/
publicclassOrderTest{
@org.junit.Test
publicvoidcalculatePrice(){
//这个商品是鞋子,123块钱一双
ProductproductShoes=newProduct();
productShoes.setName("shoes");
productShoes.setPrice(123);
//这个商品是袜子,8块钱一双
ProductproductSocket=newProduct();
productSocket.setName("socket");
productSocket.setPrice(8);
//这是一个老客户,打七折
Customercustomer=newCustomer();
customer.setDiscount(0.7);
//这个客户下了一个单
Orderorder=newOrder();
order.setCustomer(customer);
//买了一双鞋子,两双袜子
OrderLineorderLineShoes=newOrderLine(1,productShoes);
OrderLineorderLineSocket=newOrderLine(2,productSocket);
List<OrderLine>orderLineList=newArrayList<OrderLine>();
orderLineList.add(orderLineShoes);
orderLineList.add(orderLineSocket);
order.setOrderLineList(orderLineList);
//算一算总共多少钱
doublepriceActual=order.calculatePrice();
Assert.assertEquals("97.3",String.valueOf(priceActual));
}
}
测试用例的输出
productname:shoesprice:123.0number:1orderlineprice:123.0
productname:socketprice:8.0number:2orderlineprice:16.0
orderbaseprice:139.0
orderdiscountedprice:97.3
标签: UML序列图
相关文章
本节和大家学习一下如何Visio画UML用例图,UML用例图主要用来图示化系统的主事件流程,它主要用来描述客户的需求,即用户希望系统具备的完成一定功能的动作。 UML用例图简介 首先看一下......
2021-06-25 865 Visio,画,UML,用例,图,只需,八步,轻松,实现,本节,
下载了visio 2019的光盘映像(其他地方下载也是一样的),就安装了。之前下载过2016的,但是我的电脑已经安装过office2016,也是光盘映像方式安装的,所以提示冲突了,改为2019的下载再安装就......
2021-06-25 830 Visio,Visio2016,Visio激活,Visio2016激活
1.一般化关系(Generalization),所谓一般化通常指的就是继承关系,这里会有一般化(Generalization)及具体化(Specialization) 一般化的UML图例如下: 2.关联关系(Association),关联关系可以是单向或双向,但......
2021-06-25 241 visio,UML,类图,中的,关系,一般化,关系,
软件安装 一:链接: https://pan.baidu.com/s/10021SpYTPLbsT6WIKMEcKQ 提取码: r9dd 安装完毕打开visio可以看到产品未激活,先关闭,进行下面的破解激活。 软件破解 链接: https://pan.baidu.com/s/1aisfdMnOI6DR_BAKw......
2021-06-25 20 Visio,2013,64位,下载,安装,以及,破解,激活,完美,
设置visio里面的开发工具 使用指针工具将整个图全部选中,开发工具拆分将图在两个交点处分成两个部分可以选中各个部分分别移动。 图形拆分 图形裁剪 使用指针工具将整个图全部选中,开......
2021-06-25 175 visio,图形,组合,拆分,修剪,功能,设置,visio,里,