1.3.1.
Object Oriented Software Design
Object Oriented Software Design methodology is a modular software design approach. Unified
Modelling Language (UML) is used to design a software system based on object oriented design
methodology.
1.3.1.1. UML
UML stands for ‘Unified Modelling Language’. It is standardized in 1997 by the OMG (Object
Management Group). It matches with the growing complexity of systems.
It is used for both software and systems engineering. Now a days it is the de facto standard for
Software Modelling for Object Oriented Design.
It is graphical in nature, making the design easily understandable.
UML being graphical, recommends various diagrams to be generated as part of the design. There are
tools available for drawing such diagrams and there are tools available to translate the design to code
(containing stubs) in desired programming language (such as C++, Java etc).
Fig 1.3.1.1 illustrated different diagrams recommended by UML 2.0. As a designer, we need not
generate all the diagrams. It should be done on need basis and may vary from project to project. The
designer should decide on which all diagrams to make for his/her design. The most important diagram
is the ‘Class Diagram’ which we will deal with in the subsequent sections.
Fig 1.3.1.1. UML 2.0 Diagrams
Source:
http://archive.oredev.org/download/18.5bd7fa0510edb4a8ce4800019180/1385353960592/
Bruce_Douglass_-_Workshop_Real-Time_UML.pdf
1.3.1.2. Class Diagram
1.3.1.2.1. Object and Class
Let us start with the concept of Object and Class.
An object is a run-time entity that may occupies memory at some specific point in time. It is a data
structure that also provides services that act on that data. An object exists at run-time only.
An object
o has behaviour (methods)
o has data (attributes)
o has optionally a state
A class is the specification of a set of objects that share a common structure and behaviours.
Objects are said to be instances of the class.
Classes have
o Attributes
o Methods
1.3.1.2.2. Attributes and Operations
Attributes are the data specified within a class (or encapsulated within an object)
Operation is a service that the class may be requested to perform.
Methods are the implementation of the operations.
Example: Classes Representing ‘Data Structures’.
Data Structure Attributes Operations
Stack TopOfStack: int Push
Size: int Pop
Element: DATA Full
Empty
Queue Head: int Insert
Tail: int Remove
Size: int Full
Element: DATA Empty
Linked List Next: Node pointer Insert
Previous: Node pointer Remove
Element: DATA Next
Previous
Tree Left: Node pointer Insert
Right: Node pointer Remove
Element: DATA Next
Previous
1.3.1.2.3. Class
All instantiable classes have two special methods:
Constructor: Knows how to create an instance of the class
Destructor: Knows how to remove an instance of the class
There are some classes which are not instantiated, because their specification is not complete. They
are called ‘Abstract Classes’. These classes define the operations, but not implement the methods.
But abstract classes can be instantiated by derived classes.
In C++, abstract class is defined as a class having at least one pure virtual operation.
Example of a pure virtual function in C++:
virtual void resetDevice() = 0;
Abstract classes and pure virtual operations are identified by italics in UML.
1.3.1.2.4. Types of Visibility
There are different types of visibility for the attributes and methods of a classes, which are
following.
Private: Only methods inside the same class can access the private attribute or method. Private
members are indicated by ‘–’ in UML.
Protected: Only methods inside the same class and derived classes can access the protected
attribute or method. Protected members are indicated by ‘#’ in UML.
Public: Public attribute or method can be accessed by anyone outside the class. Public members
are indicated by ‘+’ in UML.
Package (rarely used): Only elements inside the same package can access the package attribute
or method. Package members are indicated by ‘~’ in UML.
1.3.1.2.5. Representation of Classes in UML
In UML, a class is represented by a rectangle having three vertical division. These three inner
rectangles contain the followings in a top to bottom order.
Class name
Class attributes (i.e. data members, variables)
Class operations (i.e. methods)
Modifiers are the symbols prepended to the class attributes and operations as per their visibility
discussed in the previous section. Followings are the modifiers as per the visibility.
o Private: -
o Public: +
o Protected: #
o Static: Underlined (i.e. shared among all members of the class)
o Package: ~
As mentioned earlier, abstract classes are shown in italics.
Fig 1.3.1.1 shows the representation of a class in UML. It also shows an example of a ‘Car Controller’
class, which is a part of an elevator system.
Fig. 1.3.1.1. Class representation in UML