1. Dependency:
A dependency is a weak relationship between two classes.
In this example, there is dependency between Point and LineSegment, because LineSegment's draw() operation uses the Point class.
It indicates that LineSegment has to know about Point, event if it has no attribute of that type.
2. Association:
Association is a relationship where all objects have their own lifecycle and there is no owner.
Let's make an example of Teacher and Student. Multiple students can associate with single teacher, and single student can associate with multiple teachers.
But there is no ownership between the objects and both have their own lifecycle. Both can create/delete independently.
1> Bi-directional association:
Associations are bi-directional by default, so both classes know about each other and about the relationship between them.
In the diagram below, any instance of Student can have 1~* Teachers, and any instance of Teacher can have 1~30 Students.
2> Uni-directional association:
Association can also be uni-directional, where one class knows about the other class and the relationship but the other class does not.
In the diagram below, Customer class knows about any number of Products purchased, but the Product class knows nothing about the Customer.
Pruduct class doesn't even know about the existence of Customer class.
3. Aggregation: ("has-a" relationship)
Aggregation is a specialized form of Association where all objects have their own lifecycle, but there is ownership and child object cannot belong to another parent object[1].
Association differs from Aggregation only in that Association does not imply any containment.
A single CPU cannot belong to multiple computers, but if we dismantle the computer, the CPU will not be destroyed.
4. Composition: ("is-a" relationship)
Composition is again a specialized form(strong type) of Aggregation and we can call this a "death" relationship. It is a strong type of aggregation.
Child object doesn't have its own lifecycle. And if parent object is deleted, all child object will also be deleted.
Let's take agagin an example of house and rooms. House can contain multiple rooms, there is no independent lifecycle of room.
5. Additional knowledge points:
1) Generally, it is better to use attributes only for types you would not draw on the diagram, such as primitive types.
Diagram below is deprecated.
Diagram below is encouraged.
2) Sample
[1]: There are some debates upon the defination of Aggregation. Please refer to Reference Links(1)
Reference Links:
1) http://stackoverflow.com/questions/885937/difference-between-association-aggregation-and-composition
2) http://stackoverflow.com/questions/1874049/uml-arrows-pointers-explanation/2293763#2293763
3) http://stackoverflow.com/questions/15487372/bi-directional-and-uni-directional-associations-uml
4) http://www.classdraw.com/help.htm
5) http://msdn.microsoft.com/en-us/library/dd409416(v=vs.100).aspx
相关推荐
在UML类图中,常见的有以下几种关系: 泛化(Generalization), 实现(Realization),关联(Association),聚合(Aggregation),组合(Composition),依赖(Dependency) 泛化(Generalization) 【泛化关系】:是一种...
UML,全称为统一建模语言(Unified Modeling Language),是一种标准化的图形化语言,用于软件系统的设计和架构的可视化表达。UML中的六大关系——依赖、泛化(类属)、关联、实现、聚合和组合,构成了理解软件系统...
- **聚合与组合 (Aggregation and Composition)**:解释了这两种关系的区别。 - **派生属性 (Derived Properties)**:介绍了如何在类图中表示派生属性。 - **接口与抽象类 (Interfaces and Abstract Classes)**:...
- **聚合(Aggregation)与组合(Composition)**: 都是关联的特殊形式,表示整体与部分的关系,其中组合更为紧密,表示所有部分都属于整体,而聚合则较松散。 2. **UML的主要图** - **用例图(Use Case Diagram...
它展示了系统中类的属性、操作(方法)和类之间的关系,如关联(Association)、依赖(Dependency)、聚合(Aggregation)和组合(Composition)。类图在软件工程中非常重要,因为它直接反映了系统设计的核心要素。 ...
关联(Association)关联指的是类之间的特定对应关系,在UML中用带实线的箭头表示。按照类之间的数量对比,关联可以分为以下三种: ● 一对一关联 ● 一对多关联 ● 多对多关联 注意:关联还要以分为单向关联和...
1. **UML基本元素**:包括类(Class)、对象(Object)、接口(Interface)、用例(Use Case)、关系(Association、Aggregation、Composition)、依赖(Dependency)、泛化(Generalization)和实现(Realization)...
4. **关系**:UML中的关系包括关联(Association)、依赖(Dependency)、泛化(Generalization)、实现(Realization)、聚合(Aggregation)和组合(Composition)。这些关系揭示了系统中各元素之间的交互和层次...
**UML(统一建模语言)**是一种标准的图形化建模语言,用于软件工程和其他领域,特别是系统分析和设计。它提供了一种可视化的方式来描述软件系统的结构和行为,使得团队成员之间能够更好地理解和交流设计理念。 **...
- **关系(Relationships)**:包括关联(Association)、聚合(Aggregation)、组合(Composition)、依赖(Dependency)、泛化(Generalization)和实现(Realization)等,描述类与类之间的联系。 - **用例...
类图中的关系:1:一般化(Generalization)关系2:关联(Association)关系2.1:聚合(Aggregation)关系2.2:合成(Composition)关系3:依赖(Dependency)关系
UML基础与应用--UML类图解析 UML(Unified Modeling Language)是一种标准化的建模语言,用于描述软件系统的结构、行为和关系。UML类图是UML九种图之一,也是UML中心的图形之一。UML类图主要用于描述系统的静态结构...
UML(Unified Modeling Language)是一种标准化的建模语言,用于软件开发过程中表示系统的结构和行为。类图是UML中最基础的图表之一,它用于描绘类与类之间的静态结构关系。下面我们将详细解释UML类图中各符号的含义...
2. **UML基本元素**:包括类(Class)、对象(Object)、接口(Interface)、用例(Use Case)、关系(Relationships)如关联(Association)、聚合(Aggregation)、组合(Composition)、依赖(Dependency)等。...
**UML(统一建模语言)**是一种标准的图形化建模语言,广泛应用于软件工程领域,用于描述、可视化、构建和文档化软件系统。它为软件开发提供了一种通用的语言,使得团队成员,无论其专业背景如何,都能有效地沟通...
**UML(统一建模语言)是软件工程领域中一种重要的建模工具,它通过图形化的方式描绘系统的行为、结构和关系。UML为软件开发提供了标准化的语言,使得团队成员可以更有效地沟通和理解项目的设计。以下是对UML及其与...
**UML用户指南** UML(Unified Modeling Language)是一种标准化的通用建模语言,用于软件工程和其他领域中的系统建模。本指南将深入探讨UML的核心概念、元素、图示以及如何有效地使用它来设计和理解复杂的软件系统...
UML(Unified Modeling Language)是一种标准化的统一建模语言,用于软件工程中描述软件系统及其组件的结构和行为。类图是UML中的一种核心图表,它用来表示系统中的类、接口及其相互关系,帮助设计师清晰地表达和...
**UML(统一建模语言)简介** UML(Unified Modeling Language)是一种标准化的图形建模语言,用于软件工程中的系统分析、设计和可视化。它为软件开发团队提供了一种通用的语言,使得开发者、分析师、项目经理等...