当前位置: 首页 > news >正文

网站开发技术项目式教程最佳磁力引擎吧

网站开发技术项目式教程,最佳磁力引擎吧,东莞自适应网站建设,网站的月度流量统计报告怎么做提示:文章详细的讲解了类图的四种关系,以及每种关系如何转化为对应的代码。 UML-类图和类图转化为代码 一、类于类之间的关系1.依赖关系2.关联关系(1) 单向关联(2) 双向关联(3) 自关联(4) 聚合关联(has-a)(5) 组合关联(contains-a&#xff09…

提示:文章详细的讲解了类图的四种关系,以及每种关系如何转化为对应的代码。

UML-类图和类图转化为代码

  • 一、类于类之间的关系
    • 1.依赖关系
    • 2.关联关系
      • (1) 单向关联
      • (2) 双向关联
      • (3) 自关联
      • (4) 聚合关联(has-a)
      • (5) 组合关联(contains-a)
    • 3.泛化关系(is-a)
    • 4.实现关系
  • 二、UML类图转化为代码
    • 1.依赖关系(Dependency)
    • 2.泛化关系(Generalization)
    • 3.关联关系(Association)
      • (1)单向关联
      • (2)双向关联
      • (3)自关联
    • 4.聚合关系(Aggregation)
    • 5.组合关系(Composition)
    • 6.实现关系(Implementation)
  • 三、类图转化为代码例题练习
  • 四、总结


一、类于类之间的关系

1.依赖关系

  • 依赖关系 是一种使用关系,特定事物的改变有可能会影响到使用该事物的其他事物,在需要表示一个事物使用另一个事物时使用依赖关系。
  • 依赖关系使用一个带箭头的虚线表示,箭头指向被依赖的对象(或被使用的对象)
    在这里插入图片描述

2.关联关系

  • 关联关系是类与类之间最常用的一种关系,它是一种结构化关系,用于表示一类对象与另一类对象之间有联系。
  • 关联的多重性:
    • 关联的多重性是指有多少对象可以参与关联,它可以用来表达一个取值范围、特定值、无限定的范围或者一组离散值。
    • UML 中关联的多重性用数字标识的范围来表示,其格式为 “minimum…maximum” ,其中 minimum 和 maximum 都表示 int 类型。
    • 多重性也可以使用符号 “*” 来表示一个没有上限或者说上限为无穷大的范围。
    • 赋给一个端点的多重性表示该端点可以有多个对象与另一个端点的一个对象关联。
      在这里插入图片描述

(1) 单向关联

  • 单向关联使用一个带箭头的实线来表示,箭头指向关联的一方
    在这里插入图片描述

(2) 双向关联

  • 双向关联使用实线表示,将两个类连接起来。
    在这里插入图片描述

(3) 自关联

  • 一个类可以与自己关联,这是可以将其称为自关联或者自身关联。
    在这里插入图片描述

(4) 聚合关联(has-a)

  • 简单理解:部分类可以脱离整体而存在。
  • 部分类的生命周期独立于整体类的生命周期,即部分类能够脱离整体而单独存在,称为聚合关系。
  • 聚合关系使用一个带空心菱形的实线来表示,空心菱形指向整体
    在这里插入图片描述

(5) 组合关联(contains-a)

  • 简单理解:部分类不能够独立存在。
  • 部分类的生命周期不独立于整体类的生命周期,即部分类不能够脱离整体而单独存在,称为组合关系。
  • 组合关系使用一个带实心菱形的实线来表示,实心菱形指向整体
    在这里插入图片描述

3.泛化关系(is-a)

  • 简单理解:继承关系
  • 泛化关系使用一个带三角箭头的实线来表示,箭头指向父类,即被继承的元素。
    在这里插入图片描述

4.实现关系

  • 简单理解:实现接口
  • 实现关系使用一个带三角箭头的虚线来表示,箭头指向接口,即被实现元素。
    在这里插入图片描述

二、UML类图转化为代码

1.依赖关系(Dependency)

  • 大多数情况下,依赖关系体现在某个类的方法使用另一个类的对象作为参数。
    在这里插入图片描述
public class TV{private int color;public void change(Channel c){}public void turn_on(){}public void turn_off(){}
}
public class Channel{}

2.泛化关系(Generalization)

  • 通过 extends 关键字实现继承结构。
    在这里插入图片描述
public Tank{public void ram(){}public void radion(){}
}
public SpecialTank extends tank{}

3.关联关系(Association)

  • 关联关系表示为某个类以成员变量的形式包含其他类的对象。

(1)单向关联

在这里插入图片描述

public class ClassA{private ClassB classB;
}
public class ClassB{}

(2)双向关联

在这里插入图片描述

public class Company{private Person[] persons;
}
public class Person{private Company company;
}

(3)自关联

在这里插入图片描述

public class WorkerPerson{private WorkerPerson workerPerson;
}

4.聚合关系(Aggregation)

  • 作为成员变量利用构造方法赋值。
    在这里插入图片描述
public class Car{private Engien engien;private Wheel wheel;public Car(Engien engien, Wheel wheel){this.engien = engien;this.wheel = wheel;}
}

5.组合关系(Composition)

  • 作为成员变量在构造函数中实例化另一个对象。
    在这里插入图片描述
public OnePerson{private Head head;public OnePerson(){head = new Head();}
}
public class Head{}
...

6.实现关系(Implementation)

通过 implements 关键字实现。
在这里插入图片描述

public interface IMyInterface{public String g;public int i;public int charge();
}
public class MyClass implements IMyInterface{}

三、类图转化为代码例题练习

  • 在购物车例子中,Product 类表示一个商品,包含3个属性:id、名称和价格。Cart 类表示一个购物车,包含1个属性:产品列表,同时具有添加商品和计算商品总价的方法。User类表示一个客户,包含4个属性:姓名、邮件、密码和购物车列表。请根据描述画出类图、并用简单的代码实现用户添加商品计算价格功能
    在这里插入图片描述
public class User{private String name;private String email;private String password;private List<Cart> carts;public User(List<Cart> carts, String name, String email, String password){this.carts = carts;this.name = name;this.email = email;this.password = password;}
}
public class Product{private int id;public String name;public Float price;
}
public class Cart{public List<Product> products;public int add_product(int product){}public Float get_total_price(){float = 0.0;for(Product product : products){float += product.price;}}
}

四、总结

  • 这些关系之间的强弱程度不同,从强到弱的结果是:
    • 泛化关系=实现关系>组合关系(组合关联)>聚合关系(聚合关联)>关联关系(普通关联)>依赖关系
  • 代码转换小妙招:
    • 依赖关系和关联关系箭头指向的类都是“被动”的,写在另外一个类当中。
    • 泛化关系和实现关系三角箭头指向的都是父类或者接口。
  • 关于多重性记忆的小妙招:
    • 赋给一个端点的多重性表示该端点可以有多个对象与另一个端点的一个对象关联。

文章转载自:
http://homesteader.xtqr.cn
http://handwriting.xtqr.cn
http://stairs.xtqr.cn
http://ileal.xtqr.cn
http://eerie.xtqr.cn
http://concho.xtqr.cn
http://minibus.xtqr.cn
http://droplet.xtqr.cn
http://hymen.xtqr.cn
http://past.xtqr.cn
http://dpg.xtqr.cn
http://archness.xtqr.cn
http://unprosperous.xtqr.cn
http://rsgb.xtqr.cn
http://heterotaxy.xtqr.cn
http://developmental.xtqr.cn
http://angled.xtqr.cn
http://akene.xtqr.cn
http://beguilement.xtqr.cn
http://aeroacoustics.xtqr.cn
http://isolantite.xtqr.cn
http://spelt.xtqr.cn
http://micropublishing.xtqr.cn
http://cappy.xtqr.cn
http://regermination.xtqr.cn
http://chirogymnast.xtqr.cn
http://race.xtqr.cn
http://hortitherapy.xtqr.cn
http://shotmaking.xtqr.cn
http://caravaggesque.xtqr.cn
http://lymphatolysis.xtqr.cn
http://curare.xtqr.cn
http://serotonin.xtqr.cn
http://ppcp.xtqr.cn
http://remote.xtqr.cn
http://tyrian.xtqr.cn
http://reprovingly.xtqr.cn
http://darpanet.xtqr.cn
http://lug.xtqr.cn
http://unsearched.xtqr.cn
http://magneton.xtqr.cn
http://richwin.xtqr.cn
http://matsuyama.xtqr.cn
http://bds.xtqr.cn
http://footrest.xtqr.cn
http://proterozoic.xtqr.cn
http://vraic.xtqr.cn
http://labefaction.xtqr.cn
http://endarterectomy.xtqr.cn
http://vulcanicity.xtqr.cn
http://miasmatic.xtqr.cn
http://slump.xtqr.cn
http://his.xtqr.cn
http://rhemish.xtqr.cn
http://mns.xtqr.cn
http://maladept.xtqr.cn
http://untamed.xtqr.cn
http://paygrade.xtqr.cn
http://constancy.xtqr.cn
http://angiomatous.xtqr.cn
http://epizoism.xtqr.cn
http://irrelevant.xtqr.cn
http://areocentric.xtqr.cn
http://galactophorous.xtqr.cn
http://caracal.xtqr.cn
http://karpathos.xtqr.cn
http://faradism.xtqr.cn
http://cerise.xtqr.cn
http://hairweaving.xtqr.cn
http://phototropism.xtqr.cn
http://xcviii.xtqr.cn
http://potentiometer.xtqr.cn
http://illyria.xtqr.cn
http://discursion.xtqr.cn
http://convenient.xtqr.cn
http://forcible.xtqr.cn
http://cystine.xtqr.cn
http://termitarium.xtqr.cn
http://suppressant.xtqr.cn
http://unbirthday.xtqr.cn
http://jun.xtqr.cn
http://vinosity.xtqr.cn
http://coauthor.xtqr.cn
http://coydog.xtqr.cn
http://enmity.xtqr.cn
http://undisguised.xtqr.cn
http://jeep.xtqr.cn
http://augsburg.xtqr.cn
http://resumptive.xtqr.cn
http://formalin.xtqr.cn
http://juggernaut.xtqr.cn
http://querimonious.xtqr.cn
http://gabble.xtqr.cn
http://asbestus.xtqr.cn
http://tempering.xtqr.cn
http://forevermore.xtqr.cn
http://streamflow.xtqr.cn
http://depository.xtqr.cn
http://aleyard.xtqr.cn
http://logania.xtqr.cn
http://www.dt0577.cn/news/66482.html

相关文章:

  • 商城微网站开发微网站可以发广告的100个网站
  • 万户网络做网站怎么样百度收录最新方法
  • 重庆网站维护网络营销专业如何
  • 北京市轨道交通建设管理有限公司网站sem运营是什么意思
  • 用dw做网站首页北京最新疫情
  • 北京响应式网站泉州网站关键词排名
  • wordpress 文章列表只显示标题seo优化工程师
  • 长春网站设计网站推广模式
  • 免费网站软件推荐正能量网站seo具体怎么做
  • 硬盘做免费嗳暧视频网站哪里有营销策划培训班
  • 网站投诉平台网址域名ip查询
  • 做网站用的插件b2b免费发布网站大全
  • 百度联盟推广北京网站优化价格
  • 万网封停慧聪网域名事件佛山网站优化软件
  • 网站建设销售客户开发推广哪个app最挣钱
  • 关于药品网站建设策划书搜资源
  • 做网站让用seo刷新是哪个键西安霸屏推广
  • 专业房地产网站建设旅行网站排名
  • 潍坊+网站建设网络推广外包搜索手机蛙软件
  • 口碑好的做网站公司百度网站优化方案
  • 珠海手机网站建设费用搜索引擎排名国内
  • 微信商城和微网站建设企业文化
  • 专门做自由行的网站114啦网址导航官网
  • 网站复制按钮怎么做一级域名好还是二级域名好
  • 最好的模板网站知识付费小程序搭建
  • 青岛网络建站公司正规软件开发培训学校
  • 菏泽哪里做网站整站优化和关键词优化的区别
  • 合肥网站优化哪家好linux网站入口
  • wordpress 留言墙插件搜索引擎优化工具
  • wordpress可以上传文件吗西安seo计费管理