The class diagram is the main building block of object oriented
modelling. It is used both for general conceptual modelling of the systematics
of the application, and for detailed modelling translating the models into
programming code. Class diagrams can also be used for data modeling. The
classes in a class diagram represent both the main objects, interactions in the
application and the classes to be programmed.
A class diagram is an illustration of the relationships and source
code dependencies among classes in the Unified Modeling Language (UML). In this
context, a class defines the methods and variables in an object, which is a
specific entity in a program or the unit of code representing that entity.
Class diagrams are useful in all forms of object-oriented programming (OOP).
The concept is several years old but has been refined as OOP modeling paradigms
have evolved.
In a class diagram, the classes are arranged in groups that share
common characteristics. A class diagram resembles a flowchart in which classes
are portrayed as boxes, each box having three rectangles inside. The top
rectangle contains the name of the class; the middle rectangle contains the
attributes of the class; the lower rectangle contains the methods, also called
operations, of the class. Lines, which may have arrows at one or both ends,
connect the boxes. These lines define the relationships, also called
associations, between the classes.
Introduction
A class with three sections.
In the diagram, classes are represented with boxes which contain
three parts:
- The top part contains the name of the class
- The middle part contains the attributes of the class
- The bottom part gives the methods or operations the class can take or undertake
In the design of a system, a number of classes are identified and
grouped together in a class diagram which helps to determine the static
relations between those objects. With detailed modelling, the classes of the
conceptual design are often split into a number of subclasses.
In order to further describe the behaviour of systems, these class
diagrams can be complemented by state diagram or UML state machine.
Scope
The UML specifies two types of scope for members: instance
and classifier.
- Classifier members are commonly recognized as “static” in many programming languages. The scope is the class itself.
- Attribute values are equal for all instances
- Method invocation does not affect the instance’s state
- Instance members are scoped to a specific instance.
- Attribute values may vary between instances
- Method invocation may affect the instance’s state (i.e., change instance’s attributes)
To indicate a classifier scope for a member, its name must be
underlined. Otherwise, instance scope is assumed by default.
Relationships
A relationship is a general term covering the specific types of
logical connections found on class and object diagrams. UML shows the following
relationships:
Instance level relationships
Links
A Link is the basic relationship among objects.
Association
Class diagram example of association between two classes
An association represents a family of links. Binary
associations (with two ends) are normally represented as a line. An association
can be named, and the ends of an association can be adorned with role names,
ownership indicators, multiplicity, visibility, and other properties.
There are four different types of association: bi-directional, uni-directional, Aggregation (includes Composition aggregation) and Reflexive. Bi-directional and uni-directional associations are the most common ones.
For instance, a flight class is associated with a plane class bi-directionally. Association represents the static relationship shared among the objects of two classes. Example: "department offers courses", is an association relation.
There are four different types of association: bi-directional, uni-directional, Aggregation (includes Composition aggregation) and Reflexive. Bi-directional and uni-directional associations are the most common ones.
For instance, a flight class is associated with a plane class bi-directionally. Association represents the static relationship shared among the objects of two classes. Example: "department offers courses", is an association relation.
Aggregation
Class diagram showing Aggregation between two classes
Aggregation is a variant of the "has a" association relationship;
aggregation is more specific than association. It is an association that
represents a part-whole or part-of relationship. As a type of association, an
aggregation can be named and have the same adornments that an association can.
However, an aggregation may not involve more than two classes.
Aggregation can occur when a class is a collection or container of other
classes, but where the contained classes do not have a strong life cycle
dependency on the container—essentially, if the container is destroyed, its
contents are not.
In UML, it is graphically represented as a hollow diamond
shape on the containing class end of the tree with a single line that connects
the contained class to the containing class. The aggregate is semantically an
extended object that is treated as a unit in many operations, although
physically it is made of several lesser objects.
Composition
Class diagram showing Composition between two classes at top and
Aggregation between two classes at bottom
Composition is a stronger variant of the "owns a" association
relationship; composition is more specific than aggregation.
Composition usually has a strong life cycle dependency between instances
of the container class and instances of the contained class(es): If the
container is destroyed, normally every instance that it contains is destroyed
as well. (Note that, where allowed, a part can be removed from a composite
before the composite is deleted, and thus not be deleted as part of the
composite.)
The UML graphical representation of a composition relationship is a filled diamond shape on the containing class end of the tree of lines that connect contained class(es) to the containing class.
Differences between composition and aggregation
When attempting to represent real-world whole-part relationships,
e.g., an engine is a part of a car, the composition relationship is most
appropriate. However, when representing a software or database relationship,
e.g., car model engine ENG01 is part of a car model CM01, an aggregation
relationship is best, as the engine, ENG01 may be also part of a different car
model. Thus the aggregation relationship is often called "catalog"
containment to distinguish it from composition's "physical"
containment.
As you create your class diagram, you can set the visibility of
each attribute and operation in the properties window, or by clicking to open a
pop-up menu in the diagram. Convenient fast editing buttons and a specialized
class diagram toolbar are also provided to help you easily add elements. UModel
identifies the visibility property of each attribute and operation with a
unique pictorial icon. The icons are keyed to indicate whether an attribute is
public, protected, or private.
sumber : http://en.wikipedia.org/wiki/Class_diagram
No comments:
Post a Comment