association,aggregation,composition,dependency

来源:互联网 发布:2015淘宝天猫交易额 编辑:程序博客网 时间:2024/05/07 19:26

依赖(dependency)就是一个类A使用到了另一个类B,而这种使用关系是具有偶然性的、临时性的、非常弱的,但是B类的变化会影响到A;表现在代码层面,为类B作为参数被类A在某个method方法中使用;

关联(association),聚合(aggregation)和组合(composition)属于一类都是associates type的一种。

下面一段是UML Specification上的一段

7.3.2 AggregationKind (from Kernel)AggregationKind is an enumeration type that specifies the literals for defining the kind of aggregation of a property.GeneralizationsNone36 UML Superstructure Specification, v2.4.1DescriptionAggregationKind is an enumeration of the following literal values:• noneIndicates that the property has no aggregation.• sharedIndicates that the property has a shared aggregation.       //聚合• compositeIndicates that the property is aggregated compositely, i.e., the composite object has responsibility for the existence             //组合and storage of the composed objects (parts).Semantic Variation PointsPrecise semantics of shared aggregation varies by application area and modeler.The order and way in which part instances are created is not defined.

关联(association):这里的关联关系分的比较细,把相互关联和有方向的关联区分开了,相互他体现的是两个类、或者类与接口之间语义级别的一种强依赖关系,是一种长期的稳定的关系;表现在代码层面,为被关联类以类属性的形式出现在关联类中,也可能是关联类引用了一个类型为被关联类的全局变量;


有方向的关联(DirectedAssociation):是关联的一种特别形式,是单向的;表现在代码层面,为被关联类B以类属性的形式出现在关联类A中,也可能是关联类A引用了一个类型为被关联类B的全局变量;


聚合关系(Aggregation):聚合是关联关系的一种特例,他体现的是整体与部分、拥有的关系,即has-a的关系,此时整体与部分之间是可分离的,他们可以具有各自的生命周期,部分可以属于多个整体对象,也可以为多个整体对象共享;表现在代码层面,A类中有B类类型的域,B实例化后传给A,B还可以传给别人。


组合关系(Composition):组合也是关联关系的一种特例,他体现的是一种contains-a的关系,这种关系比聚合更强,也称为强聚合;他同样体现整体与部分间的关系,但此时整体与部分是不可分的,整体的生命周期结束也就意味着部分的生命周期结束;表现在代码层面,A中有B类类型的域,B在A中实例化。


0 0
原创粉丝点击