11.3 Static Modeling Diagrams


11.3 Static Modeling Diagrams

The static modeling diagrams describe the static characteristics of a system or application. These modeling UML diagrams describe the various classes in the application, the relationship among the classes, and the objects. These diagrams are also categorized as static diagrams.

11.3.1 Class Diagrams

The UML class diagrams describe the structure of the classes in an application model and their relationships. These diagrams are the main static descriptions of the application. These diagrams consist of the class descriptions and their relationships. These diagrams are constructed during the analysis phase of the development process. A clear idea of the problem domain is essential to decide which classes are required in the model of the application.

As explained in previous chapters, the basic graphical representation of a class is a rectangle divided into three sections or parts. The top part of the rectangle contains the name of the class. The middle part of the rectangle contains the attribute names. The bottom part of the rectangle contains the operations of the class. Figure 11.2 shows a graphical representation of class Person.


Figure 11.2: Class Person.

In addition to the basic represenation of a class, the type of each attribute and the access mode of each feature is also normally shown. In Figure 11.2, the type shown for attribute name is string. The type shown for attribute age is integer. The access mode of the two attributes is private, shown by a - sign before the name of the attribute. The access mode for the two operationss is public, shown by + sign before the name of the operation. For features with protected access mode, the # sign would be included before the name of the feature.

The object diagram is often shown as a variation of the class diagram. Figure 11.3 shows a UML object diagram. The main differences of an object diagram are:

  • The name of the class of the object is underlined. For example, :Person denotes an object of class Person.

  • The attributes of the object include their current values. This defines the current state of the object. The types of the attributes are not included because these are defined in the class.

  • The operations of the object are included. When these are left out, they are defined in the corresponding class.


Figure 11.3: An object of class Person.

11.3.2 Associations

An association is a relationship between two or more classes. The simplest association is the binary association, which is represented by a solid line connecting two classes in the corresponding UML diagram. The name of the association may be included just above the line. The association name may also include a solid small triangle to indicate the direction in which to read the association name. The associations can also include roles, which are shown at the ends of the line, close to the corresponding classes.

A binary association is shown in Figure 11.4. It shows a binary relation between class Person and class Ball. The name of the association here is plays_with, and the roles are customer and provider.

click to expand
Figure 11.4: A binary association between classes Person and Ball.

A class can be used to describe or define an association. This notation is used when it is useful to define attributes and operations to an association. An association class is drawn as a class symbol connected by a dashed line to the association. The name of the class is the name assigned to the association.

11.3.3 Multiplicity of the Association

The multiplicity of an association is the number of objects of one class in a relationship with a number of objects of the other class. A range of numbers can be specified for each class in the diagram. If l denotes the lower bound in a range, and if u denotes the upper bound in the range, then the notation l..u corresponds to the range. When a star is used, it indicates an unlimited upper bound.

The star at the side of class Ball in Figure 11.4 denotes that there can be zero or many objects of this class in the association with class Person. There is only one object of class Person.

11.3.4 Aggregation

An n-ary association is a relationship that involves more than two classes. When a relationship exists among classes where some classes are contained within other classes, the relationship is known as aggregation, or part-whole relationship or containment. In simple aggregation, the larger class is called the owner class; the smaller classes are called component classes. Often, classes are not contained in other classes but are organized in the communication mechanism through the class representing the whole.

With UML aggregation diagrams, this relationship is denoted with a diamond at the owner class side of the association. Figure 11.5 shows an owner class Computer, in associations with three component classes, CPU, Memory, and Input/Output.

click to expand
Figure 11.5: An aggregation relationship with four classes.

Composition is a stronger form of aggregation in which the owner class has exclusive ownership of the contained class. In UML notation, it is shown as a solid diamond at the end of the line that represents the association.

11.3.5 Inheritance

Inheritance is a vertical relationship among classes. It allows for enhanced class reuse, that is, the ability to develop a new class using a predefined and previously developed class. This allows the sharing of some classes across several different applications. The new class inherits the characteristics of the existing and more general class, to incorporate the characteristics into the new class.

In most practical applications, classes are arranged in hierarchies, with the most general class at the top of the hierarchy. A parent class is also called the super class (or the base class). A derived class inherits the characteristics (all attributes and operations) of its parent class. A derived class can be further inherited to lower-level classes. In the UML class diagram, an arrow with an empty head points from a subclass (the derived class) to its parent class.

A subclass can be:

  • An extension of the parent class, if it includes its own attributes and operations, in addition to the derived characteristics it inherits from the parent class

  • A specialized version of the parent class, if it overrides (redefines) one or more of the derived characteristics inherited from its parent class

This is the basic idea of class reuse with inheritance, which has as its main advantage that the definition and development of a class takes much less time than if the class were developed from scratch. This is the reason why class reuse is important.

In UML terminology, generalization is the association between a general class and a more specialized class (or extended class). This association is also called inheritance, and it is an important relationship between classes. Therefore, in modeling, it is useful to show this in the class diagrams. In the UML class diagram, an arrow points from a class (the derived class) to its parent class.

Caution

When a class inherits the characteristics from more than one parent class, the mechanism is called multiple inheritance. Most object-oriented programming languages support multiple inheritance (KJP and Java do not).

Figure 11.6 illustrates a simple class hierarchy with inheritance. The parent class is Polygon and the subclasses are: Triangle, Rectangle, and Parallelogram that inherit the features from the parent class.

click to expand
Figure 11.6: An inheritance relationship.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net