内网网站建设方面政策,呼叫中心,网站访问量排行榜,注册网站需要多少钱?文章目录程序设计要素1.可读性2.健壮性3.优化4.复用性5.可扩展性设计类的关系遵循的原则1、 高内聚低耦合2、面向对象开发中 “针对接口编程优于针对实现编程”#xff0c;”组合优于继承” 的总体设计类与类之间的关系#xff08;即事物关系#xff09; A is-a B 泛化…
文章目录程序设计要素1.可读性2.健壮性3.优化4.复用性5.可扩展性设计类的关系遵循的原则1、 高内聚低耦合2、面向对象开发中 “针对接口编程优于针对实现编程””组合优于继承” 的总体设计类与类之间的关系即事物关系 A is-a B 泛化继承实现 A has-a B 包含紧密程度组合 聚合 关联 A need-a B 依赖依赖 Java程序体现的形式为 程序设计要素 1.可读性 名字 缩进 注释 2.健壮性 判断严谨 3.优化 结构 性能 内存 4.复用性 抽取方法 类 5.可扩展性 抽象 接口 面向配置文件 设计类的关系遵循的原则
1、 高内聚低耦合 耦合度紧密程度 从强到弱依次是 继承实现组合聚合关联依赖 2、面向对象开发中 “针对接口编程优于针对实现编程””组合优于继承” 的总体设计 类与类之间的关系即事物关系 类与类之间关系即事物关系有如下6种 继承Generalization又叫作泛化关系、 实现Realization关系 组合Composition 关系 聚合Aggregate关系 关联Association关系 依赖Dependency关系 A is-a B 泛化继承实现
1、在 继承关系 中子类继承父类的所有功能父类所具有的属性、方法子类都应该有。除了与父类一致的信息子类中还包括额外的信息。例如公交车、出租车都是车
2、接口包括抽象类是方法的集合在 实现关系 中类实现了接口类中的方法实现了接口声明的所有方法。例如人、动物都吃饭都睡觉 A has-a B 包含紧密程度组合 聚合 关联
3、 关联关系 是类与类之间最常用的一种关系表示一类对象与另一类对象之间有联系。组合、聚合也属于关联关系只是关联关系的类间关系比其他两种关系要弱。比如说人有汽车人有电脑整体和部分的关系可以分割后来形成在一起 关联关系有4种 双向关联、 单向关联、 自关联、 多重性关联 例如汽车和司机一辆汽车对应特定的司机一个司机也可以开多辆车 Association is a relation between two separate classes which establishes through their Objects. Association can be 1、one-to-one, 2、one-to-many, i.e. Bank can have many employees 3、many-to-one, 4、many-to-many. In Object-Oriented programming, an Object communicates to another object to use functionality and services provided by that object. Composition and Aggregation are the two forms of association. 4、 聚合关系 也表示类之间整体与部分的关系成员对象是整体对象的一部分但是成员对象可以脱离整体对象独立存在。例如工人和工作服是整体与部分的关系但是可以分开没有共同的生命周期。工作服可以穿在别的司机身上工人也可以换别人的工作服。再比如说汽车和车轮电脑和主板。
It is a special form of Association where: 1、It represents Has-A’s relationship. 2、It is a unidirectional association i.e. a one-way relationship. For example, a department can have students but vice versa is not possible and thus unidirectional in nature. 3、In Aggregation, both the entries can survive individually which means ending one entity will not affect the other entity. When do we use Aggregation ?? Code reuse is best achieved by aggregation. 5、 组合关系 表示类之间整体与部分的关系整体与部分有一致的生存期。一旦整体对象不存在部分对象也将不存在整体和部分是同生共死的关系。 皮之不存毛将焉附 例如人和脑袋人和大脑人和心脏 Composition is a restricted form of Aggregation in which two entities are highly dependent on each other. 1、It represents part-of relationship. 2、In composition, both entities are dependent on each other. 3、When there is a composition between two entities, the composed object cannot exist without the other entity. For example, Book is Part-of Library. If Library gets destroyed then All books within that particular library will be destroyed. i.e. books can not exist without libraries. That’s why it is composition. Aggregation vs Composition 1. Dependency: Aggregation implies a relationship where the child can exist independently of the parent. For example, Bank and Employee, delete the Bank and the Employee still exist. whereas Composition implies a relationship where the child cannot exist independent of the parent. Example: Human and heart, heart don’t exist separate to a Human 2. Type of Relationship: Aggregation relation is “has-a” and composition is “part-of” relation. 3. Type of association: Composition is a strong Association whereas Aggregation is a weak Association. A need-a B 依赖依赖
6、 依赖关系 是一种“使用”关系特定事物的改变有可能会影响到使用该事物的其他事物当需要表示一个事物使用另一个事物时使用依赖关系。 在大多数情况下依赖关系体现在某个类的方法使用另一个类的对象作为参数。例如汽车依赖汽油如果没有汽油则汽车将无法行驶。 在这6种类关系中 组合、聚合和关联的代码结构一样可以从关系的强弱来理解 各类关系从强到弱依次是 继承实现组合聚合关联依赖 -----------------------------------------------------摘自《设计模式就该这样学基于经典框架源码和真实业务场景》谭勇德 ------------------------------------------------------------------------摘自Article–《Association, Composition and Aggregation in Java》 Java程序体现的形式为
has a 一个类的对象当做另一个类的属性来存储 对于赋值 可以在构造方法里赋值可以通过set方法赋值 need a一个类的方法中使用到了另一个类的对象 对于赋值: 可以在方法中自己创建可以在方法中传递进来 -----------------------------------------------------------------------------------------------------------------------------------------------自己总结