Advanced classes in UML
Advanced classes in UML
Suryateja Pericherla
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.
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.
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:
The graphical representation of the classifiers is as follows:
Let’s look at the advanced features (specific information that can be represented) of classes in UML.
Example:
A classifier scoped feature is graphically represented by underlining the feature within the classifier. All other normal features are treated as instanced scope.
Example:
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:
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:
[visibility] name [multiplicity] [: type] [=initial value] [{property string}]
Examples:
The three predefined properties that can be used with attributes in UML are:
Example:
[visibility] name [(parameters-list)] [: return-type] [{property-string}]
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:
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:
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.
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:
The graphical representation of the classifiers is as follows:
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: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:A classifier scoped feature is graphically represented by underlining the feature within the classifier. All other normal features are treated as instanced 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:
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:
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:
The three predefined properties that can be used with attributes in UML are:
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:
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:
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:
Common Modeling Techniques
Modeling the semantic of a class
To model the semantics of a class:- Specify the responsibilities of the class in a note and attach it to the class with a dependency relationship.
- Specify the semantics of a class as a whole in a note stereotyped with “semantics”.
- 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.
- Specify the pre-conditions and post-conditions for operations using structured text in a note.
- Specify a state machine for a class which represents different states the object undergoes.
- Specify a collaboration that represents a class.
Comments
Post a Comment