Fundamentals of Software Engineering Fourth Edition Rajib Mall
Fundamentals of Software Engineering Fourth Edition Rajib Mall
com******
Chapter
7
OBJECT MODELLING USING UML
Note that any design is a model of the solution, whereas any model of the
problem is an analysis model. In this chapter, we shall discuss how to
document a model using a modelling language. In the subsequent chapter, we
shall discuss a design process that can be used to iteratively refine an analysis
model into a design model.
In the context of model construction, we need to carefully understand the
distinction between a modelling language and a design process, since we shall
use these two terms frequently in our discussions.
Modelling language: A modelling language consists of a set of notations
using which design and analysis models are documented.
Design process: A design process addresses the following issue: “Given a
problem description, how to systematically work out the design solution to the
problem?” In other words, a design process consists of a step by step
procedure (or recipe) using which a problem description can be converted into
a design solution. A design process is, at times, also referred to as a design
methodology. In this text, we shall use the terms design process and design
methodology interchangeably.
A model can be documented using a modelling language such as unified
modelling language (UML). Over the last decade, UML has become immensely
popular. UML has also been accepted by ISO as a standard for modelling
object-oriented systems. In this Chapter, we primarily discuss the syntax and
semantics of UML. However, before discussing the nitty- gritty of the syntax
and semantics of UML, we review a few basic concepts and terminologies that
have come to be associated with object-orientation.
Objects
In the object-oriented approach, it is convenient to imagine the working
of a software in terms of a set of interacting objects. This is analogous
to the way object manipulations take place in a real-world manual
system for getting some work done. For example, consider a manually
operated library system. For issuing a book, an issue register needs to
be filled up and then the return date needs to be stamped on the book.
In an object-oriented library automation software, analogous activities
involving the book object and the issue register object take place.
Each object in an object-oriented program usually represents a tangible real-
world entity such as a library member, a book, an issue register, etc. However
while solving a problem, it becomes advantageous at times to consider certain
conceptual entities (e.g., a scheduler, a controller, etc.) as objects as well. This
simplifies the solution and helps to arrive at a good design.
A key advantage of considering a system as a set of objects is the following:
Each object essentially consists of some data that is private to the object
and a set of functions (termed as operations or methods ) that operate on
those data. This aspect has pictorially been illustrated in Figure 7.2. Observe
that the data of the object can only be accessed by the methods of the object.
Consequently, the only access point to the data for the external objects is
through the invocation of the methods of the object. In fact, the methods of
an object have the sole authority to operate on the data that is private to the
object. In other words, no object can directly access the data of any other
object.Therefore, each object can be thought of as hiding its internal data
from other objects. However, an object can access the private data of another
object by invoking the methods supported by that object. This mechanism of
hiding data from other objects is popularly known as the principle of data
hiding o r data abstraction. Data hiding promotes high cohesion and low
coupling among objects, and therefore is considered to be an important
principle that can help one to arrive at a reasonably good design.
As already mentioned, each object stores some data and supports certain
operations on the stored data. As an example, consider the libraryMember
object of a library automation application. The private data of a libraryMember
object can be the following:
• name of the member
• membership number
• address
• phone number
• e-mail address
• date when admitted as a member
• membership expiry date
• books outstanding
The operations supported by a libraryMember object can be the following:
• issue-book
• find-books-outstanding
• find-books-overdue
• return-book
• find-membership-details
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
The data stored internally in an object are called its attributes, and the
operations supported by an object are called its methods.
Though the terminologies associated with object-orientation are simple and
well-defined, a word of caution here: the term ‘object’ is often used rather
loosely in the literature and also in this text. Often an ‘object’ would mean a
single entity. However, at other times, we shall use it to refer to a group of
similar objects (class). In this text, usually the context of use would resolve
the ambiguity, if any.
Class
Similar objects constitute a class. That is, all the objects constituting a
class possess similar attributes and methods. For example, the set of all
library members would constitute the class LibraryMember in a library
automation application. In this case, each library member object has
attributes such as member name, membership number, member
address, etc. and also has methods such as issue-book,
returnbook, etc. Once we define a class, it can be used as a template
for object creation.
Let us now investigate the important question as to whether a class is an
abstract data type (ADT). To be able to answer this question, we must first be
aware of the basic definition of an ADT. We first discuss the same in a
nutshell. There are two things that are inherent to an ADT—abstract data and
data type. In programming language theory, a data type identifies a group of
variables having a particular behaviour. A data type can be instantiated to
create a variable. For example, int is a type in C++ language. When we write
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
Methods are the only means available to other objects in a software for
accessing and manipulating the data of another object. The set of valid
messages to an object constitutes its protocol. Let us now try to understand
the distinction between a message and a method.
In Smalltalk, an object could request the services (i.e., invoke methods) of
other objects by sending messages to them. The idea was that the mechanism
of message passing would lead to weak coupling among objects. Though this
was an important feature of Smalltalk, yet the programmers who were trying
to migrate from procedural programming to object-oriented programming,
found it to be a paradigm shift and therefore difficult to accept. Subsequently,
C++ implemented message passing by method invocation
(similar to a function call). This was rapidly accepted by the programmers.
Later object-oriented languages such as Java have followed the same trait of
retaining the method invocation feature, that is normally associated with the
procedural languages.
Inheritance
The inheritance feature allows one to define a new class by incrementally
extending the features of an existing class. The original class is called the base
class (also called superclass o r parent class ) and the new class obtained
through inheritance is called the derived class (also called a subclass or a child
class ). The derived class is said to inherit the features of the base class. An
example of inheritance has been shown in Figure 7.3. In Figure 7.3, observe
that the classes Faculty, Students, and Staff have been derived
from the base class LibraryMember through an inheritance relationship
(note the special type of arrow that has been used to draw it). The inheritance
Observe that in Figure 7.3 the classes Faculty, Student, and Staff
are all special types of library members. Several things are common among
the members. These include attributes such as membership id, member name
and address, date on which books issued out, etc. However, for the different
categories of members, the issue procedure differs since different types
members are issued books for different durations. We can convey as much by
saying that the classes Faculty, Staff, and Students are special types
of LibraryMember classes. Using the inheritance relationship, different
classes can be arranged in a class hierarchy (or class tree) as shown in Figure
7.3.
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
In addition to inheriting all the data and methods of the base class, a
derived class usually defines some new data and methods. A derived class
may even redefine a method which already exists in the base class.
Redefinition of a method which already exists in its base class is termed as
method overriding.
When a new definition of a method that existed in the base class is provided in a
derived class, the method is said to be overridden in the derived class.
Let us examine how code reuse and simplicity of design come about while
using the inheritance mechanism. If certain methods or data are present in
several classes, then instead of defining these methods and data in each of
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
the classes separately, these methods and data are defined only once in the
base class and then inherited by each of its subclasses. For example, in the
Library Information System example of Figure 7.4, each category of member
(that is, Faculty, Student, and Staff) need to store the following data
—member-name, member-address, and membership-number.
Therefore, these data are defined in the base class LibraryMember and are
inherited by all it’s subclasses. Another advantage that accrues from the use of
the inheritance mechanism is the conceptual simplification brought about
through the reduction of the number of independent features of the different
classes and incremental understanding of the different classes becomes
possible. Thus, inheritance can be considered as a use of the abstraction
mechanism we discussed in Chapter 1. The class at the root of an inheritance
hierarchy (e.g. LibraryMember in Figure 7.3) is the simplest to understand— as
it has the least number of data and method members compared to all other
classes in the hierarchy. The classes at the leaf-level of the inheritance
hierarchy have the maximum number of features (data and method members)
because they inherit features of all their ancestors, and therefore turn out to
be the toughest to understand.
In a large class hierarchy, it is easier to first understand the root class and
then to recursively understand its children classes in the hierarchy until the
leaf level classes are reached.
Multiple inheritance
Construction of the class relationships for a given problem consists of
identifying and representing four types of relations—inheritance,
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
Consider the following example of a class that is derived from two base
classes through the use of the multiple inheritance mechanism. In this
example, in an academic institute research students can also be employed as
staff of the institute, then some of the characteristics of the Research class
are similar to the Student class (e.g., every student would have a roll
number) while some other characteristics (e.g., having a basic salary and
employee number, etc.) might be similar to the Staff class. Using multiple
inheritance the class Research can inherit features from both the classes
Student and Staff. In Figure 7.4, we have shown the class Research to
be derived from both the Student and Staff classes by drawing inheritance
arrows to both the parent classes of the Research class.
its id. For example, for an object of ElectiveSubject class e1 to invoke the
printName() method one of the registered students s1 , it must execute the
code s1 .printName(). Thus, it should have stored the id s1 of the
registered student as an attribute. The association relationship can either be
bidirectional or unidirectional. That is, both the associated classes know each
other (store each others ids). We have graphically shown this association
between Student class and ElectiveSubject in Figure 7.5(a).
Consider another example of association between two classes: Library
Member borrows Books. Here, borrows is the association between the class
LibraryMember and the class Book. The association relation would imply that
given a book, it would be possible to determine the borrower and vice versa.
n-ary association
Binary association between classes is very commonly encountered in design
problems. However, there can be situations where three or more different
classes can be involved in an association. As an example of a ternary
association, consider the following—A person books a ticket for a certain
show. Here, an association exists among the classes Person, Ticket, and Show.
This example of ternary association relationship has pictorially been shown in
Figure 7.5(b).
Figure 7.5: Example of (a) binary (b) ternary (c) unary association.
When two classes are associated, the relationship between two objects of
the corresponding classes is called a link.
An association describes a group of similar links. Alternatively, we can say that a link
can be considered as an instance of an association relation. Let us now try to identify
the association relation from the text description of a problem.
An association between two classes simply means that zero or more links
may be present among the objects of the associated classes at any time
during execution.
Mathematically, a link can be considered to be a tuple. Consider the
following example. “Amit has borrowed the book Graph Theory.” Here, a link
named borrowed has got established between the objects Amit and the Graph
Theory book. This link can also be expressed as the ordered pair of object
instances {Amit,Graph Theory}.
Dependency
A class is said to be dependent on another class, if any changes to the latter
class necessitates a change to be made to the dependent class.
A dependency relation between two classes shows that any change made to the
independent class would require the corresponding change to be made to the
dependent class.
Abstract class
Classes that are not intended to produce instances of themselves are called
abstract classes. In other words, an abstract class cannot be instantiated. If
an abstract class cannot be instantiated to create objects, then what is the use
of defining an abstract class? Abstract classes merely exist so that behaviour
common to a variety of classes can be factored into one common location,
where they can be defined once. Definition of an abstract class helps to push
reusable code up in the class hierarchy, thereby enhancing code reuse.
By using abstract classes, code reuse can be enhanced and the effort required to
develop software brought down.
Composition
B is a permanent part of A
A is made up of Bs
A is a permanent collection of Bs
Aggregation
B is a part of A
A contains B
A is a collection of Bs
Inheritance
A is a kind of B
A is a specialisation of B
A behaves like B
Association
A delegates to B
A needs help from B
A collaborates with B. Here collaborates with can be any of a large
variety of collaborations that are possible among classes such as employs,
credits, precedes, succeeds, etc.
Abstraction
Let us first recapitulate how the abstraction mechanism works (we had already
discussed this basic mechanism in Section 1.3.2). Abstraction is the selective
examination of certain aspects of a problem while ignoring all the remaining
aspects of a problem. In other words, the main purpose of using the
abstraction mechanism is to consider only those aspects of the problem that
are relevant to a given purpose and to suppress all aspects of the problem
that are not relevant.
The abstraction mechanism allows us to represent a problem in a simpler way by
considering only those aspects that are relevant to some purpose and omitting all
other details that are irrelevant.
other. Each object only provides a set of methods, which other objects can use
for accessing and manipulating this private information of the object. For
example, a stack object might store its internal data either in the form of an
array of values or in the form of a linked list. Other objects would not know
how exactly this object has stored its data (i.e. data is abstracted) and how it
internally manipulates its data. What they would know is the set of methods
such as push, pop, and top-of-stack that it provides to the other objects for
accessing and manipulating the data.
An important advantage of the principle of data abstraction is that it reduces coupling
among various objects, Therefore, it leads to a reduction of the overall complexity of
a design, and helps in easy maintenance and code reuse.
Encapsulation
The data of an object is encapsulated within its methods. To access the
data internal to an object, other objects have to invoke its methods, and
cannot directly access the data. This concept is schematically shown in
Figure 7.8. Observe from Figure 7.8 that there is no way for an object to
access the data private to another object, other than by invoking its
methods. Encapsulation offers the following three important advantages:
Polymorphism
Polymorphism literally means poly (many) morphis m (forms). Remember
that in Chemistry, diamond, graphite, and coal are called polymorphic
forms of carbon. That is, though diamond, coal, and graphite are
essentially carbon, they behave very differently. In an analogous manner
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
produced on a method call cannot be predicted at compile time and can only
be observed at run time.
Method overriding
We have already explained the method overriding principle in which a derived
class provides a new definition to a method of the base class.
Let us now understand how dynamic binding works by making use of the
above two mechanisms. Suppose we have defined a class hierarchy of
different geometric shapes for a graphical drawing package as shown in Figure
7.10. As can be seen from the figure, Shape is an abstract class and the
classes Circle, Rectangle, and Line are directly derived from it and
further the classes Ellipse, Square and Cube have been derived to form
an inheritance hierarchy. Now, suppose the draw method is declared in the
Shape class and is overridden in each derived class. Further, suppose a set of
different types of Shape objects have been created one by one. By Liskov’s
substitution principle, the created Shape objects can be stored in an array of
type Shape. If the different types of geometric objects making up a drawing
are stored in an array of type Shape, then a call to the draw method for each
object would take care to display the appropriate drawing element. That is,
the same draw call to a Shape object would take care of drawing the
appropriate drawing object. Observe that due to dynamic binding, a call to the
draw method of the shape class takes care of displaying the appropriate
drawing object residing in the shape array. This is illustrated in the code
segment shown in Figure 7.11.
Figure 7.11: Traditional code versus object-oriented code incorporating the dynamic binding feature.
It can be easily seen from Figure 7.11 that the use of dynamic binding, the
object-oriented code is much more concise, understandable, and intellectually
appealing as compared to equivalent procedural code. Further, suppose that in
the example program segment, it is later found necessary to handle a new
graphics drawing primitive, say ellipse. Then, the procedural code has to be
changed by adding a new if-then-else clause. However, in case of an
objectoriented program, the code need not change, only a new class called
Ellipse has to be derived in the Shape hierarchy.
We can now summarise the mechanism of dynamic binding as follows:
Even when the method of an object of the base class is invoked, an appropriate
overridden method of a derived class would be invoked depending on the exact
object that may have been assigned at the run-time to the object of the base class.
Genericity
Genericity is the ability to parameterise class definitions. For example,
while defining a class stack of different types of elements such as
integer stack, character stack, floating-point stack, etc.; genericity
permits us to define a generic class of type stack and later instantiate it
either as an integer stack, a character stack, or a floating-point stack as
may be required. This can be achieved by assigning a suitable value to a
parameter used in the generic class definition.
Persistence
Objects usually get destroyed once a program completes its execution.
Persistent objects are stored permanently. That is, they live across
different executions. An object can be made persistent by maintaining
copies of the object in a secondary storage or in a database.
Agents
A passive object is one that performs some action only when requested
through invocation of some of its methods. An agent (also called an
active object), on the other hand, monitors events occurring in the
application and takes actions autonomously. Agents are used in
applications such as monitoring exceptions. For example, in a database
application such as accounting, an agent may monitor the balance sheet
and would alert the user whenever inconsistencies arise in a balance
sheet due to some improper transaction taking place.
Widget
The term widget stands for window object. A widget is a primitive object
used for graphical user interface (GUI) design. More complex graphical
user interface design primitives (widgets) can be derived from the basic
widget using the inheritance mechanism. A widget maintains internal
data such as the geometry of the window, back ground and fore ground
colors of the window, cursor shape and size, etc. The methods
supported by a widget manipulate the stored data and carry out
operations such as resize window, iconify window, destroy window, etc.
Widgets are becoming the standard components of GUI design. This has
given rise to the technique of component-based user interface
development. We shall discuss more about widgets and
componentbased user interface development in Chapter 9 where we
discuss GUI design.
Advantages of OOD
In the last couple of decades since OOD has come into existence, it has
found widespread acceptance in industry as well as in academic circles.
The main reason for the popularity of OOD is that it holds out the
following promises:
Out of all the above mentioned advantages, it is usually agreed that the
chief advantage of OOD is improved productivity—which comes about due to a
variety of factors, such as the following:
Disadvantages of OOD
The following are some of the prominent disadvantages inherent to the
object paradigm:
One of the objectives of the developers of UML was to keep the notations of
UML independent of any specific design methodology, so that it can be used
along with any specific design methodology. In this respect, UML is different
from its predecessors (e.g., OMT, Booch’s methodology, etc.) where the
notations supported by the modelling languages were closely tied to the
corresponding design methodologies.
Needless to say that UML has borrowed many concepts from these modeling
techniques. Concepts and notations from especially the first three
methodologies have heavily been drawn upon. The influence of various object
modeling techniques on UML is shown schematically in Figure 7.12. As shown
in Figure 7.12, OMT had the most profound influence on UML.
Figure 7.12: Schematic representation of the impact of different object modelling techniques on
UML.
UML was adopted by object management group (OMG) as a de facto
standard in 1997. Actually, OMG is not a standards formulating body, but is an
association of industries that tries to facilitate early formulation of standards.
OMG aims to promote consensus notations and techniques with the hope that
if the usage becomes wide-spread, then they would automatically become
standards. For more information on OMG, see www.omg.org. With widespread
use of UML, ISO adopted UML a standard (ISO 19805) in 2005, and with this
UML has become an official standard; this has further enhanced the use of
UML.
UML is more complex than its antecedents. This is only natural and expected
because it is intended to be more comprehensive and applicable to a wider
gamut of problems than any of the notations that existed before UML. UML
contains an extensive set of notations to help document several aspects
(views) of a design solution through many types of diagrams. UML has
successfully been used to model both large and small problems. The elegance
of UML, its adoption by OMG, and subsequently by ISO as well as a strong
industry backing have helped UML to find wide spread acceptance. UML is now
being used in academic and research institutions as well as in large number of
software development projects world-wide. It is interesting to note that the
use of UML is not restricted to the software industry alone. As an example of
UML’s use outside the software development problems, some car
manufacturers are planning to use UML for their “build-to-order” initiative.
Many of the UML notations are difficult to draw by hand on a paper and are
©
best drawn using a CASE tool such as Rational Rose (see www.rational.com )
or MagicDraw (www.magicdraw.com ). Now several free UML CASE tools are
also available on the web. Most of the available CASE tools help to refine an
initial object model to final design, and these also automatically generate code
templates in a variety of languages, once the UML models have been
constructed.
What is a model?
Before we discuss the features of UML in detail, it is important to understand
what exactly is meant by a model, and why is it necessary to create a model.
Analysis
Specification
Design
Coding
Visualisation and understanding of an implementation.
Testing, etc.
Once a system has been modelled from all the required perspectives, the
constructed models can be refined to get the actual implementation of the
system.
UML diagrams can capture the following views (models) of a system:
User’s view
Structural view
Behaviourial view
Implementation view
Environmental view
Figure 7.14 shows the different views that the UML diagrams can document.
Observe that the users’ view is shown as the central view. This is because
based on the users’ view, all other views are developed and all views need to
conform to the user’s view. Most of the object oriented analysis and design
methodologies, including the one we are going to discuss in Chapter 8 require
us to iterate among the different views several times to arrive at the final
design. We first provide a brief overview of the different views of a system
which can be documented using UML. In the subsequent sections, the
diagrams used to realize the important views are discussed.
Users’ view
This view defines the functionalities made available by the system to its users.
The users’ view captures the view of the system in terms of the functionalities
offered by the system to its users.
The users’ view is a black-box view of the system where the internal
structure, the dynamic behaviour of different system components, the
implementation etc. are not captured. The users’ view is very different from all
1
other views in the sense that it is a functional model compared to all other
2
views that are essentially object models.
The users’ view can be considered as the central view and all other views
are required to conform to this view. This thinking is in fact the crux of any
user centric development style. It is indeed remarkable that even for
objectoriented development, we need a functional view. That is because, after
all, a user considers a system as providing a set of functionalities.
Structural view
The structural view defines the structure of the problem (or the solution) in
terms of the kinds of objects (classes) important to the understanding of the
working of a system and to its implementation. It also captures the
relationships among the classes (objects).
The structural model is also called the static model, since the structure of a system
does not change with time.
Behaviourial view
The behaviourial view captures how objects interact with each other in
time to realise the system behaviour. The system behaviour captures the
time-dependent (dynamic) behaviour of the system. It therefore
constitutes the dynamic model of the system.
Implementation view
This view captures the important components of the system and their
interdependencies. For example, the implementation view might show
the GUI part, the middleware, and the database part as the different
parts and also would capture their interdependencies.
Environmental view
This view models how the different components are implemented on
different pieces of hardware.
For any given problem, should one construct all the views using all the
diagrams provided by UML? The answer is No. For a simple system, the use
case model, class diagram, and one of the interaction diagrams may be
sufficient. For a system in which the objects undergo many state changes, a
state chart diagram may be necessary. For a system, which is implemented on
a large number of hardware components, a deployment diagram may be
necessary. So, the type of models to be constructed depends on the problem
at hand. Rosenberg provides an analogy [Ros 2000] saying that “Just like you
do not use all the words listed in the dictionary while writing a prose, you do
not use all the UML diagrams and modeling elements while modeling a
system.”
A simple way to find all the use cases of a system is to ask the question
—“What all can the different categories of users do by using the system?”
Thus, for the library information system (LIS), the use cases could be:
• issue-book
• query-book
• return-book • create-member
• add-book, etc.
Roughly speaking, the use cases correspond to the high-level functional
requirements that we discussed in Chapter 4. We can also say that the use
cases partition the system behaviour into transactions, such that each
transaction performs some useful action from the user’s point of view. Each
transaction, to complete, may involve multiple message exchanges between
the user and the system.
The purpose of a use case is to define a piece of coherent behaviour without
revealing the internal structure of the system. The use cases do not mention
any specific algorithm to be used nor the internal data representation, internal
Normally, each use case is independent of the other use cases. However,
implicit dependencies among use cases may exist because of dependencies
that may exist among use cases at the implementation level due to factors
such as shared resources, objects, or functions. For example, in the Library
Automation System example, renew-book and reserve-book are two
independent use cases. But, in actual implementation of renew-book, a check
is to be made to see if any book has been reserved by a previous execution of
the reserve-book use case. Another example of dependence among use
cases is the following. In the Bookshop Automation Software,
updateinventory and sale-book are two independent use cases. But,
during execution of sale-book there is an implicit dependency on
updateinventory. Since when sufficient quantity is unavailable in the
inventory, sale-book cannot operate until the inventory is replenished using
updateinventory.
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
The use case model is an important analysis and design artifact. As already
mentioned, other UML models must conform to this model in any use
casedriven (also called as the user-centric) analysis and development
approach. It should be remembered that the “use case model” is not really an
objectoriented model according to a strict definition of the term.
In contrast to all other types of UML diagrams, the use case model represents a
functional or process model of a system.
The stereotype construct when used to annotate a basic symbol, can give slightly
different meaning to the basic symbol— thereby eliminating the need to have several
symbols whose meanings differ slightly from each other.
Text description
Each ellipse in a use case diagram, by itself conveys very little
information, other than giving a hazy idea about the use case.
Therefore, every use case diagram should be accompanied by a text
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
Example 7.3 The use case diagram of the Super market prize scheme
described in example 6.3 is shown in Figure 7.16.
Text description
U1: register-customer: Using this use case, the customer can register
himself by providing the necessary details.
Scenario 1: Mainline sequence
1. Customer: select register customer option
2 . System: display prompt to enter name, address, and
telephone number.
3. Customer: enter the necessary values
4: System: display the generated id and the message that
the customer has successfully been registered.
Scenario 2: At step 4 of mainline sequence
4 : System: displays the message that the customer has
already registered.
Scenario 3: At step 4 of mainline sequence
4: System: displays message that some input information
have not been entered. The system displays a prompt to
enter the missing values.
U2: register-sales: Using this use case, the clerk can register the details of
the purchase made by a customer.
Scenario 1: Mainline sequence
1. Clerk: selects the register sales option.
2. System: displays prompt to enter the purchase
details and the id of the customer.
3. Clerk: enters the required details.
4 : System: displays a message of having successfully
registered the sale.
U3: select-winners. Using this use case, the manager can generate the
winner list.
Scenario 2: Mainline sequence
1. Manager: selects the select-winner option.
2. System: displays the gold coin and the surprise gift
winner list.
Identification of the use cases involves brain storming and reviewing the
SRS document. Typically, the high-level requirements specified in the
SRS document correspond to the use cases. In the absence of a
wellformulated SRS document, a popular method of identifying the use
cases is actor-based. This involves first identifying the different types of
actors and their usage of the system. Subsequently, for each actor the
different functions that they might initiate or participate are identified.
For example, for a Library Automation System, the categories of users
can be members, librarian, and the accountant. Each user typically
focuses on a set of functionalities. Foe example, the member typically
concerns himself with book issue, return, and renewal aspects. The
librarian concerns himself with creation and deletion of the member and
book records. The accountant concerns itself with the amount collected
from membership fees and the expenses aspects.
Complex use cases need to be factored into simpler use cases. This
would not only make the behaviour associated with the use case much
more comprehensible, but also make the corresponding interaction
diagrams more tractable. Without decomposition, the interaction
It is desirable to factor out common usage such as error handling from a set
of use cases. This makes analysis of the class design much simpler and
elegant. However, a word of caution here. Factoring of use cases should not
be done except for achieving the above two objectives. From the design point
of view, it is not advantageous to break up a use case into many smaller parts
just for the sake of it. UML offers three factoring mechanisms as discussed
further.
Generalisation
Use case generalisation can be used when you have one use case that is
similar to another, but does something slightly differently or something more.
Generalisation works the same way with use cases as it does with classes. The
child use case inherits the behaviour and meaning of the present use case.
The notation is the same too (See Figure 7.17). It is important to remember
that the base and the derived use cases are separate use cases and should
have separate text descriptions.
Includes
The includes relationship in the older versions of UML (prior to UML 1.1)
was known as the uses relationship. The includes relationship implies
one use case includes the behaviour of another use case in its sequence
of events and actions. The includes relationship is appropriate when you
have a chunk of behaviour that is similar across a number of use cases.
The factoring of such behaviour will help in not repeating the
specification and implementation across different use cases. Thus, the
includes relationship explores the issue of reuse by factoring out the
commonality across use cases. It can also be gainfully employed to
decompose a large and complex use case into more manageable parts.
As shown in Figure 7.18, the includes relationship is represented using a
predefined stereotype <<include>>. In the includes relationship, a base use
case compulsorily and automatically includes the behaviour of the common
use case. As shown in example Figure 7.19, the use cases issue-book and
renew-book both include check-reservation use case. The base use
case may include several use cases. In such cases, it may interleave their
associated common use cases together. The common use case becomes a
separate use case and independent text description should be provided for it.
Extends
The main idea behind the extends relationship among use cases is that it
allows you show optional system behaviour. An optional system behaviour is
executed only if certain conditions hold, otherwise the optional behaviour is
not executed. This relationship among use cases is also predefined as a
stereotype as shown in Figure 7.20.
Organisation
When the use cases are factored, they are organised hierarchically. The
highlevel use cases are refined into a set of smaller and more refined use
cases as shown in Figure 7.21. Top-level use cases are super-ordinate to the
refined use cases. The refined use cases are sub-ordinate to the top-level use
cases. Note that only the complex use cases should be decomposed and
organised in a hierarchy. It is not necessary to decompose the simple use
cases.
subsystem-level use cases specify the services offered by the subsystems. Any
number of levels involving the subsystems may be utilized. In the lowest level
of the use case hierarchy, the class-level use cases specify the functional
fragments or operations offered by the classes.
Classes
The classes represent entities with common features, i.e., attributes and
operations. Classes are represented as solid outline rectangles with
compartments. Classes have a mandatory name compartment where the
name is written centered in boldface. The class name is usually written
using mixed case convention and begins with an uppercase (e.g.
LibraryMember). Object names on the other hand, are written using a
mixed case convention, but starts with a small case letter (e.g.,
studentMember). Class names are usually chosen to be singular
nouns. An example of various representations of a class are shown in
Figure 7.23.
Classes have optional attributes and operations compartments. A class may
appear on several diagrams. Its attributes and operations are suppressed on
all but one diagram. But, one may wonder why there are so many
representations for a class! The answer is that these different notations are
used depending on the amount of information about a class is available. At the
start of the design process, only the names of the classes is identified. This is
the most abstract representation for the class. Later in the design process the
methods for the class and the attributes are identified and the other more
concrete notations are used.
is only returned from the operation; or “inout” indicating that the parameter is
used for passing data into the operation and getting result from the operation.
The default is “in”.
An operation may have a return type consisting of a single return type
expression, e.g., issueBook(in bookName):Boolean. An operation may have a
class scope (i.e., shared among all the objects of the class) and is denoted by
underlining the operation name.
Often a distinction is made between the terms operation and method. An
operation is something that is supported by a class and invoked by objects of
other classes. There can be multiple methods implementing the same
operation. We have pointed out earlier that this is called static polymorphism.
The method names can be the same; however, it should be possible to
distinguish among the methods by examining their parameters. Thus, the
terms operation a n d method are distinguishable only when there is
polymorphism. When there is only a single method implementing an
operation, the terms method and operation are indistinguishable and can be
used interchangeably.
Association
Association between two classes is represented by drawing a straight line
between the concerned classes. Figure 7.24 illustrates the graphical
representation of the association relation. The name of the association is
written along side the association line. An arrowhead may be placed on the
association line to indicate the reading direction of the association. The
arrowhead should not be misunderstood to be indicating the direction of a
pointer implementing an association. On each side of the association relation,
the multiplicity is noted as an individual number or as a value range. The
multiplicity indicates how many instances of one class are associated with the
other. Value ranges of multiplicity are noted by specifying the minimum and
maximum value, separated by two dots, e.g. 1..5. An asterisk is used as a wild
card and means many (zero or more). The association of Figure 7.24 should
be read as “Many books may be borrowed by a LibraryMember”. Usually,
associations (and links) appear as verbs in the problem statement.
Aggregation
Aggregation is a special type of association relation where the involved
classes are not only associated to each other, but a whole-part
relationship exists between them. That is, the aggregate object not only
knows the addresses of its parts and therefore invoke the methods of its
parts, but also takes the responsibility of creating and destroying its
parts. An example of aggregation, a book register is an aggregation of
book objects. Books can be added to the register and deleted as and
when required.
Aggregation is represented by an empty diamond symbol at the aggregate
end of a relationship. An example of the aggregation relationship has been
shown in Fig 7.25. The figure represents the fact that a document can be
considered as an aggregation of paragraphs. Each paragraph can in turn be
considered as aggregation of lines. Observe that the number 1 is annotated at
the diamond end, and a * is annotated at the other end. This means that one
document can have many paragraphs. On the other hand, if we wanted to
indicate that a document consists of exactly 10 paragraphs, then we would
have written number 10 in place of the (*).
The aggregation relationship cannot be reflexive (i.e. recursive). That is, an
object cannot contain objects of the same class as itself. Also, the aggregation
relation is not symmetric. That is, two classes A and B cannot contain
instances of each other. However, the aggregation relationship can be
transitive. In this case, aggregation may consist of an arbitrary number of
levels. As an example of a transitive aggregation relationship, please see
Figure 7.25.
Composition
Composition is a stricter form of aggregation, in which the parts are
existence-dependent on the whole. This means that the life of the parts
cannot exist outside the whole. In other words, the lifeline of the whole
and the part are identical. When the whole is created, the parts are
created and when the whole is destroyed, the parts are destroyed.
A typical example of composition is an order object where after placing the
order, no item in the order cannot be changed. If any changes to any of the
order items are required after the order has been placed, then the entire order
has to be cancelled and a new order has to be placed with the changed items.
In this case, as soon as an order object is created, all the order items in it are
created and as soon as the order object is destroyed, all order items in it are
also destroyed. That is, the life of the components (order items) is the same
as the aggregate (order). The composition relationship is represented as a
filled diamond drawn at the composite-end. An example of the composition
relationship is shown in Figure 7.26.
Inheritance
The inheritance relationship is represented by means of an empty arrow
pointing from the subclass to the superclass. The arrow may be directly
drawn from the subclass to the superclass. Alternatively, when there are
Dependency
A dependency relationship is shown as a dotted arrow (see Figure 7.28)
that is drawn from the dependent class to the independent class.
Constraints
A constraint describes a condition or an integrity rule. Constraints are
typically used to describe the permissible set of values of an attribute, to
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
Object diagrams
Object diagrams shows the snapshot of the objects in a system at a point in
time. Since it shows instances of classes, rather than the classes themselves,
it is often called as an instance diagram. The objects are drawn using rounded
rectangles (see Figure 7.29).
Sometimes, especially for complex use cases, more than one interaction
diagrams may be necessary to capture the behaviour. An interaction diagram
shows a number of example objects and the messages that are passed
between the objects within the use case.
There are two kinds of interaction diagrams—sequence diagrams and
collaboration diagrams. These two diagrams are equivalent in the sense that
any one diagram can be derived automatically from the other. However, they
are both useful. These two actually portray different perspectives of behaviour
of a system and different types of inferences can be drawn from them. The
interaction diagrams play a major role in any effective objectoriented design
process. We discuss this issue in Chapter 8.
Sequence diagram
A sequence diagram shows interaction among objects as a two
dimensional chart. The chart is read from top to bottom. The objects
participating in the interaction are shown at the top of the chart as
boxes attached to a vertical dashed line. Inside the box the name of the
object is written with a colon separating it from the name of the class
and both the name of the object and the class are underlined. This
signifies that we are referring any arbitrary instance of the class. For
example, in Figure 7.30 :Book represents any arbitrary instance of the
Book class.
An object appearing at the top of the sequence diagram signifies that the
object existed even before the time the use case execution was initiated.
However, if some object is created during the execution of the use case and
participates in the interaction (e.g., a method call), then the object should be
shown at the appropriate place on the diagram where it is created.
The vertical dashed line is called the object’s lifeline. Any point on the lifeline
implies that the object exists at that point. Absence of lifeline after some point
******ebook converter DEMO - www.ebook-converter.com*******
******Created by ebook converter - www.ebook-converter.com******
indicates that the object ceases to exist after that point in time, particular
point of time. Normally, at the point if an object is destroyed, the lifeline of the
object is crossed at that point and the lifeline for the object is not drawn
beyond that point. A rectangle called the activation symbol is drawn on the
lifeline of an object to indicate the points of time at which the object is active.
Thus an activation symbol indicates that an object is active as long as the
symbol (rectangle) exists on the lifeline. Each message is indicated as an
arrow between the lifelines of two objects. The messages are shown in
chronological order from the top to the bottom. That is, reading the diagram
from the top to the bottom would show the sequence in which the messages
occur.
Each message is labelled with the message name. Some control information
can also be included. Two important types of control information are:
A condition (e.g., [invalid]) indicates that a message is sent, only if the
condition is true.
An iteration marker shows that the message is sent many times to
multiple receiver objects as would happen when you are iterating over a
collection or the elements of an array. You can also indicate the basis of
the iteration, e.g., [for every book object].
Figure 7.30: Sequence diagram for the renew book use case
The sequence diagram for the book renewal use case for the Library
Automation Software is shown in Figure 7.30. Observe that the exact objects
which participate to realise the renew book behaviour and the order in which
they interact can be clearly inferred from the sequence diagram. The
development of the sequence diagram in the development methodology
(discussed in Chapter 8) would help us to determine the responsibilities that
must be assigned to the different classes; i.e., what methods should be
supported by each class.
Collaboration diagram
A collaboration diagram shows both structural and behavioural aspects
explicitly. This is unlike a sequence diagram which shows only the behavioural
aspects. The structural aspect of a collaboration diagram consists of objects
and links among them indicating association. In this diagram, each object is
also called a collaborator. The behavioural aspect is described by the set of
messages exchanged among the different collaborators.
The link between objects is shown as a solid line and can be used to send
messages between two objects. The message is shown as a labelled arrow
placed near the link. Messages are prefixed with sequence numbers because
they are the only way to describe the relative sequencing of the messages in
this diagram.
The collaboration diagram for the example of Figure 7.30 is shown in Figure
7.31. Use of the collaboration diagrams in our development process would be
to help us to determine which classes are associated with which other classes.
Figure 7.31: Collaboration diagram for the renew book use case.
Activity diagrams are similar to the procedural flow charts. The main
difference is that activity diagrams support description of parallel activities and
synchronisation aspects involved in different activities.
Parallel activities are represented on an activity diagram by using swim
lanes. Swim lanes enable you to group activities based on who is performing
them, e.g., academic department vs. hostel office. Thus swim lanes subdivide
activities based on the responsibilities of some components. The activities in a
swim lanes can be assigned to some model elements, e.g. classes or some
component, etc. For example, in Figure 7.32 the swim lane corresponding to
the academic section, the activities that are carried out by the academic
section and the specific situation in which these are carried out are shown.
7.9 POSTSCRIPT
UML has gained rapid acceptance among practitioners and academicians over
a short time and has proved its utility in arriving at good design solutions to
software development problems.
In this text, we have kept our discussions on UML to a bare minimum and
have concentrated only on those aspects that are necessary to solve moderate
sized traditional software design problems.
Before concluding this chapter, we give an overview of some of the aspects
that we had chosen to leave out. We first discuss the package and deployment
diagrams. Since UML has undergone a significant change with the release of
UML 2.0 in 2003. We briefly mention the highlights of the improvements
brought about UML 2.0 over the UML 1.X which was our focus so far. This
significant revision was necessitated to make UML applicable to the
development of software for emerging embedded and telecommunication
domains.
Package diagram
A package is a grouping of several classes. In fact, a package diagram can be
used to group any UML artifacts. We had already discussed packaging of use
cases in Section 7.4.6. Packages are popular way of organising source code
files. Java packages are a good example which can be modelled using a
package diagram. Such package diagrams show the different class groups
(packages) and their inter dependencies. These are very useful to document
organisation of source files for large projects that have a large number of
program files. An example of a package diagram has been shown in Figure
7.34.
Component diagram
A component represents a piece of software that can be independently
purchased, upgraded, and integrated into an existing software. A
component diagram can be used to represent the physical structure of
an implementation in terms of the various components of the system. A
component diagram is typically used to achieve the following purposes:
• Organise source code to be able to construct executable releases.
• Specify dependencies among different components.
A package diagram can be used to provide a high-level view of each
component in terms the different classes it contains.
Deployment diagram
The deployment diagram shows the environmental view of a system. That
is, it captures the environment in which the software solution is
implemented. In other words, a deployment diagram shows how a
software system will be physically deployed in the hardware
environment. That is, which component will execute on which hardware
component and how they will they communicate with each other. Since
the diagram models the run time architecture of an application, this
diagram can be very useful to the system’s operation staff.
The environmental view provided by the deployment diagram is important
for complex and large software solutions that run on hardware systems
comprising multiple components. In this case, deployment diagram provides
an overview of how the different components are distributed among the
different hardware components of the system.
The collaboration diagram of UML 1.X has been renamed in UML 2.0 as
communication diagram. This renaming was necessary as the earlier name
was somewhat misleading, it shows the communications among the classes
during the execution of a use case rather than showing collaborative problem
solving.
Though a large number of new features have been introduced in UML 2.0 as
compared to 1.X, in the following subsections, we discuss only two of the
enhancements in UML2.0 through combined fragments and composite
structure diagram.
Figure 7.36: An example sequence diagram showing a combined fragment in UML 2.0.
SUMMARY
In this chapter, we first reviewed some important concepts associated
with object-orientation.
One of the primary advantages of object-orientation is increased
productivity of the software development team. The reason why object-
oriented projects achieve dramatically higher levels of productivity can
be attributed primarily due to reuse of predefined classes and partly
reuse achieved due to inheritance, and the conceptual simplicity
brought about by the object approach.
Object modelling is very important in analysing, designing, and
understanding systems. UML has rapidly gained popularity and is poised
to become a standard in object modelling.
UML can be used to construct five different views of a system using nine
different kinds of diagrams. However, it is not mandatory to construct
all views of a system using all types of diagrams in a modelling effort.
The types of models to be constructed depends on the problem at
hand.