태그 보관물: Association

UML – Association

연관 관계(Association)은 단순히 관계가 있다는 말이다. 그리고, 관계에는 단방향과 양방향이 있다. 그리고, 관계는 여러 개와 관계를 가질 수 있고, 이것은 집합적인 개념으로 Aggregation과 Composition으로 나눌 수 있다. 아래에서는 단방향과 양방향에 대해서 살펴보자.

1. 단방향

1.1 클래스 다이어그램

1.1 코드

1.1.1. C.java

public class C {
  /** */
  public D Unnamed1;
}

1.1.2. D.java

public class D {
}

2. 양방향

2.1 클래스 다이어그램

2.2 코드

2.2.1. A.java

public class A {
  /** */
  public B Unnamed1;
}

2.2.2. B.java

public class B {
  /** */
  public A Unnamed1;
}

Association Vs Aggregation Vs Composition

An Association is a channel between classes through which messages can be sent. As sending messages translates to calling methods in Java, Associations are typically (but not necessarily) implemented by references.

An Aggregation is an Association which denotes an “is part of” relationship. Unfortunately, the definition of this relationship is quite lax, so basically everyone is using his own interpretation. The only definitive (?) property is that in an instance graph, aggregations are not allowed to be circular – that is, an object can not be “a part of itself”. (or) When building new classes from existing classes using aggregation, a composite object built from other constituent objects that are its parts.Java supports aggregation of objects by reference,since objects can’t contain other objects explicitly.

A Composition adds a lifetime responsibility to Aggregation. In a garbage collected language like Java it basically means that the whole has the responsibility of preventing the garbage collector to prematurely collect the part – for example by holding a reference to it. (In a language like C++, where you need to explicitely destroy objects, Composition is a much more important concept.) Only one whole at a time can have a composition relationship to a part, but that relationship doesn’t need to last for the whole lifetime of the objects – with other words, lifetime responsibility can be handed around.

Aggregation and Composition Guidelines :

Sometimes an object is made up of other objects. For example, an airplane is made up of a fuselage, wings, engines, landing gear, flaps, and so on. A delivery shipment contains one or more packages. A team consists of two or more employees. These are all examples of the concept of aggregation, which represents 밿s part of?relationships. An engine is part of a plane, a package is part of a shipment, and an employee is part of a team. Aggregation is a specialization of association, specifying a whole-part relationship between two objects. Composition is a stronger form of aggregation where the whole and parts have coincident lifetimes, and it is very common for the whole to manage the lifecycle of its parts. From a stylistic point of view, because aggregation and composition are both specializations of association the guidelines for associations apply.

출처는 http://faq.javaranch.com/java/AssociationVsAggregationVsComposition 입니다.