UML Tutorial for Beginners
Blog containing resources for uml like lecture notes, lecture videos, lab manual, uml diagrams, objective bits, important questions and more.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: Structural Modeling. 1 Comment on Advanced Classes in UML
4.1
(51)

If you are familiar with the basics of a class and its representation, you can continue reading this article. Otherwise, first read the basics about classes in UML.

 

Introduction

 

The fundamental building block in a object-oriented system is an object or class. However, in UML, class is not the only general building block. It is only one of the general building blocks in UML, called as classifiers.

 

A classifier is a mechanism which describes structural and behavioral features in a system. Other classifiers in UML are: interfaces, datatypes, signals, components, nodes, use cases and subsystems.

 


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


Classifiers

 

A classifier is a mechanism which describes structural and behavioral features. Class is the frequently used classifier. Every classifier represents structural aspects in terms of properties and behavioral aspects in terms of operations. Beyond these basic features, there are several advanced features like multiplicity, visibility, signatures, polymorphism and others.

 

In general, all the modeling elements that can have instances are called as classifiers. For example, classes have instances known as objects. Some elements like packages and a generalization does not have instances.  Classifiers in UML are as follows:

 

uml classifiers

 

The graphical representation of the classifiers is as follows:

 

uml classifiers symbols

 

Let’s look at the advanced features (specific information that can be represented) of classes in UML.

 

Visibility

 

One of the important features that can be applied to the classifier’s attributes and operations is the visibility. The visibility feature specifies whether a classifier can be used or accessed by the other classifiers. The four access specifiers in UML are as shown below:

 

uml visibility access specifiers

 

Example:

 

uml visibility example

 

Scope

 

Another feature that can be applied to the classifier’s attributes and operations is the scope. The scope of an attribute or an operation denotes whether they have their existence in all the instances of the classifier or only one copy is available and is shared across all the instances of the classifier. The scope specifiers in UML are:

 

uml scope specifiers

 

A classifier scoped feature is graphically represented by underlining the feature within the classifier. All other normal features are treated as instanced scope.

 

Example:

 

uml scope example

 

Abstract, Root, Leaf and Polymorphic elements

 

While developing class diagrams, it is common to use generalization relationship to model generalization-specialization relationships between a group of classes.

 

The classes at the top of the hierarchy are more generalized or abstract and the classes lower in the hierarchy are more specialized. To represent abstract classes for which we cannot create instances, the class name is written in italics in UML. To represent abstract methods, we write the operation signature in italics.

 

We can also represent leaf and root classes in UML. A class which has no child classes is known as a leaf class. Such a class can be represented by writing leaf as a property under the class name.

 

Similarly, a class with no parents is known as a root class and such a class can be represented by writing root as a property as a property under the class name.

 

In class hierarchies it is common for the classes to have methods with same signatures. This feature of declaring methods with same signatures is known as polymorphism. Such methods are represented in UML by writing their signatures in italics.

 

We can also specify that a method cannot be overrided by marking the method with the leaf property written beside the method signature.

 

Example:

 

classes abstract root leaf polymorphism

 

Multiplicity

 

When modeling classes it is reasonable to assume that a class can have any number of instances. In some cases a class might not have any instances at all. Such a class with no instances is called a utility class which contains only attributes and operations with the classifier scope.

 

A class with exactly one instance is called a singleton class. Similarly other classes might have any number of instances which is the default in UML.

 

The specification of how many instances a class can have is known as multiplicity. In UML, we can mention the multiplicity as an expression in the top right hand corner of the class icon. Attributes too can have multiplicity. The multiplicity of an attribute is represented in brackets after the attribute name.

 

Example:

 

class multiplicity

 

Attributes

 

While modeling classes, it is reasonable to write only the attribute name. Along with the name, you can also specify multiplicity, visibility and scope. Apart from these features, we can also specify the type, initial value and changeability of each attribute. The syntax of an attribute in UML is:

 

[visibility] name [multiplicity] [: type] [=initial value] [{property string}]

 

Examples:

 

advanced uml attributes

 

The three predefined properties that can be used with attributes in UML are:

 

class attributes properties

 

Example:

 

advanced attributes example

 

Operations

 

While modeling classes, it is simple to write only the operation name. Along with the name we can also mention the visibility and scope. Apart from these basic details, we can also specify the return type, parameters, concurrency semantics and other features. The syntax of an operation in UML is:

 

[visibility] name [(parameters-list)] [: return-type] [{property-string}]

 

Examples:

 

advanced operations examples

 

The signature of parameter in the parameters list of an operation is as follows:

 

[direction] name :type [=initial value]

 

Direction may be anyone of the following values:

 

parameter directions

 

The operation name, parameters list and its return type is collectively known as the signature of the operation.

 

There are four predefined properties (stereotypes) that can be applied to operations, in UML. They are:

 

uml operation properties

 

Common Modeling Techniques

 

Modeling the semantic of a class

 

To model the semantics of a class:

  1. Specify the responsibilities of the class in a note and attach it to the class with a dependency relationship.
  2. Specify the semantics of a class as a whole in a note stereotyped with “semantics”.
  3. Specify the body of a method using structured text or a programming language in a note and attach it to the class or operation using a dependency relationship.
  4. Specify the pre-conditions and post-conditions for operations using structured text in a note.
  5. Specify a state machine for a class which represents different states the object undergoes.
  6. Specify a collaboration that represents a class.

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

1 Comment

You can follow any responses to this entry through the RSS 2.0 feed.

It’s more helpful if we have information about packages also.

Leave a Reply

Your email address will not be published. Required fields are marked *