1.10. Software Engineering Case Study:
Introduction to Object Technology and the UML
Now we begin our study of object
orientation. Chapters
1–7,
9
and 13 all end with a brief Software Engineering Case Study section
in which we present a carefully paced introduction to object orientation. Our
goal here is to help you develop an object-oriented way of thinking and to
introduce you to the Unified Modeling Language™
(UML®)—a graphical language that
allows people who design object-oriented software systems to use an
industry-standard notation to represent them.
In this required section, we
introduce basic object-oriented concepts and terminology. The optional sections
in Chapters
2–7,
9
and 13 present an object-oriented design and
implementation of the software for a simple automated teller machine (ATM)
system. The Software Engineering Case Study sections at the ends of Chapters
2–7
-
analyze a typical requirements
specification that describes a software system (the ATM) to be built
-
determine the objects required to implement that
system
-
determine the attributes the objects will have
-
determine the behaviors these objects will exhibit
-
specify how the objects interact with
one another to meet the system requirements
The Software Engineering Case
Study sections at the ends of Chapters
9 and 13
modify and enhance the design presented in Chapters
2–7.
Appendix
E contains a complete, working C++ implementation of the object-oriented ATM
system.
Although our case study is a
scaled-down version of an industry-level problem, we nevertheless cover many
common industry practices. You'll experience a solid introduction to
object-oriented design with the UML. Also, you'll sharpen your code-reading
skills by touring the complete, carefully written and well-documented C++
implementation of the ATM.
Basic Object Technology
Concepts
We begin our introduction to object
orientation with some key terminology. Everywhere you look in the real world you
see objects—people, animals, plants, cars, planes, buildings,
computers, monitors and so on. Humans think in terms of objects. Telephones,
houses, traffic lights, microwave ovens and water coolers are just a few more
objects we see around us every day.
We sometimes divide objects into two
categories: animate and inanimate. Animate objects are "alive" in some
sense—they move around and do things. Inanimate objects do not move on their
own. Objects of both types, however, have some things in common. They all have
attributes (e.g.,
size, shape, color and weight), and they all exhibit behaviors (e.g., a
ball rolls, bounces, inflates and deflates; a baby cries, sleeps, crawls, walks
and blinks; a car accelerates, brakes and turns; a towel absorbs water). We'll
study the kinds of attributes and behaviors that software objects have.
Humans learn about existing
objects by studying their attributes and observing their behaviors. Different
objects can have similar attributes and can exhibit similar behaviors.
Comparisons can be made, for example, between babies and adults, and between
humans and chimpanzees.
Object-oriented design
(OOD) models software in terms similar to those
that people use to describe real-world objects. It takes advantage of class
relationships, where objects of a certain class, such as a class of vehicles,
have the same characteristics—cars, trucks, little red wagons and roller skates
have much in common. OOD takes advantage of inheritance
relationships, where new classes of objects are derived by absorbing
characteristics of existing classes and adding unique characteristics of their
own. An object of class "convertible" certainly has the characteristics of the
more general class "automobile," but more specifically, the roof goes up and
down.
Object-oriented design provides a
natural and intuitive way to view the software design process—namely, modeling
objects by their attributes, behaviors and interrelationships just as we
describe real-world objects. OOD also models communication between objects. Just
as people send messages to one another (e.g., a sergeant commands a soldier to stand at attention), objects also communicate via
messages. A bank account object may receive a message to decrease its balance by
a certain amount because the customer has withdrawn that amount of money.
OOD encapsulates (i.e.,
wraps) attributes and operations (behaviors) into objects—an object's attributes and
operations are intimately tied together. Objects have the property of information hiding.
This means that objects may know how to communicate with one another across
well-defined interfaces, but normally they are not allowed to know how other objects
are implemented—implementation details are hidden within the objects themselves.
We can drive a car effectively, for instance, without knowing the details of how
engines, transmissions, brakes and exhaust systems work internally—as long as we
know how to use the accelerator pedal, the brake pedal, the steering wheel and
so on. Information hiding, as we'll see, is crucial to good software
engineering.
Languages like C++ are object
oriented. Programming in such a language is
called object-oriented programming (OOP), and it allows computer programmers to implement
object-oriented designs as working software systems. Languages like C, on the
other hand, are procedural, so programming
tends to be action oriented. In C, the unit
of programming is the function. In C++, the
unit of programming is the class from which
objects are eventually instantiated (an OOP term for "created"). C++ classes
contain functions that implement operations and data that implements
attributes.
C programmers concentrate on
writing functions. Programmers group actions that perform some common task into
functions, and group functions to form programs. Data is certainly important in
C, but the view is that data exists primarily in support of the actions that
functions perform. The verbs in a system specification help the C programmer determine the
set of functions that will work together to implement the system.
Classes, Data Members and Member
Functions
C++ programmers
concentrate on creating their own user-defined
types called classes. Each class contains data as well as the set of functions
that manipulate that data and provide services to clients (i.e., other
classes or functions that use the class). The data components of a class are
called data members. For example, a bank account class might include an
account number and a balance. The function components of a class are called
member functions (typically called methods in other
object-oriented programming languages such as Java). For example, a bank account
class might include member functions to make a deposit (increasing the balance),
make a withdrawal (decreasing the balance) and inquire what the current balance
is. You use built-in types (and other user-defined types) as the "building
blocks" for constructing new user-defined types (classes). The nouns in a system
specification help the C++ programmer determine the set of classes from which
objects are created that work together to implement the system.
Classes are to objects as blueprints
are to houses—a class is a "plan" for building an object of the class. Just as
we can build many houses from one blueprint, we can instantiate (create) many
objects from one class. You cannot cook meals in the kitchen of a blueprint; you
can cook meals in the kitchen of a house. You cannot sleep in the bedroom of a
blueprint; you can sleep in the bedroom of a house.
Classes can have relationships with
other classes. For example, in an object-oriented design of a bank, the "bank
teller" class needs to relate to other classes, such as the "customer" class,
the "cash drawer" class, the "safe" class, and so on. These relationships are
called associations.
Packaging
software as classes makes it possible for future software systems to reuse the classes.
Groups of related classes are often packaged as reusable components. Just as
realtors often say that the three most important factors affecting the price of
real estate are "location, location and location," some people in the software
development community say that the three most important factors affecting the
future of software development are "reuse, reuse and reuse."
Software Engineering Observation 1.3
|
Reuse of
existing classes when building new classes and programs saves time, money and
effort. Reuse also helps programmers build more reliable and effective systems,
because existing classes and components often have gone through extensive
testing, debugging and performance
tuning. |
Indeed, with object technology, you can
build much of the new software you'll need by combining existing classes, just
as automobile manufacturers combine interchangeable parts. Each new class you
create will have the potential to become a valuable software asset that you and
other programmers can reuse to speed and enhance the quality of future software
development efforts.
Introduction to Object-Oriented
Analysis and Design (OOAD)
To create the best solutions, you
should follow a detailed process for analyzing your project's requirements (i.e., determining what the system is supposed to do) and developing a
design that satisfies them (i.e., deciding
how the system should
do it). Ideally, you would go through this process and carefully review the
design (or have your design reviewed by other software professionals) before
writing any code. If this process involves analyzing and designing your system
from an object-oriented point of view, it is called an object-oriented analysis and design (OOAD)
process. Experienced programmers know that
analysis and design can save many hours by helping them to avoid an ill-planned
system-development approach that has to be abandoned part of the way through its
implementation, possibly wasting considerable time, money and effort.
Ideally, members of a group should
agree on a strictly defined process for solving their problem and a uniform way
of communicating the results of that process to one another. Although many
different OOAD processes exist, a single graphical language for communicating
the results of any
OOAD process has come into wide use. This language, known as the Unified
Modeling Language (UML), was developed in the mid-1990s under the initial
direction of three software methodologists—Grady Booch, James Rumbaugh and Ivar
Jacobson.
History of the UML
In the 1980s, increasing numbers of
organizations began using OOP to build their applications, and a need developed
for a standard OOAD process. Many methodologists—including Booch, Rumbaugh and
Jacobson—individually produced and promoted separate processes to satisfy this
need. Each process had its own notation, or "language" (in the form of graphical
diagrams), to convey the results of analysis and design.
By the early 1990s,
different organizations, and even divisions within the same organization, were
using their own unique processes and notations. At the same time, these
organizations also wanted to use software tools that would support their
particular processes. Software vendors found it difficult to provide tools for
so many processes. A standard notation and standard processes were needed.
In 1994,
James Rumbaugh joined Grady Booch at Rational Software Corporation (now a
division of IBM), and the two began working to unify their popular processes.
They soon were joined by Ivar Jacobson. In 1996, the group released early
versions of the UML to the software engineering community and requested
feedback. Around the same time, an organization known as the Object Management Group™ (OMG™) invited submissions for a common modeling language. The OMG
(www.omg.org) is a nonprofit organization that promotes the
standardization of object-oriented technologies by issuing guidelines and
specifications, such as the UML. Several corporations—among them HP, IBM,
Microsoft, Oracle and Rational Software—had already recognized the need for a
common modeling language. In response to the OMG's request for proposals, these
companies formed UML Partners—the consortium that developed the UML version 1.1 and
submitted it to the OMG. The OMG accepted the proposal and, in 1997, assumed
responsibility for the continuing maintenance and revision of the UML. The UML
version 2 now available marks the first major revision of the UML since the 1997
version 1.1 standard. We present UML 2 terminology and notation throughout this
book.
What Is the UML?
The UML is now the most widely
used graphical representation scheme for modeling object-oriented systems. It
has indeed unified the various popular notational schemes. Those who design
systems use the language (in the form of diagrams) to model their systems.
An attractive feature of the UML is its
flexibility. The UML is extensible (i.e., capable of being enhanced with new features)
and is independent of any particular OOAD process. UML modelers are free to use
various processes in designing systems, but all developers can now express their
designs with one standard set of graphical notations.
In our Software Engineering Case Study
sections, we present a simple, concise subset of the UML. We then use this
subset to guide you through a complete object-oriented design experience with
the UML.
UML Web Resources
For more information about the UML,
refer to the websites listed below. For additional UML sites, refer to the web
resources listed at the end of Section
2.7.
www.uml.org
This UML resource page from the Object
Management Group (OMG) provides specification documents for the UML and other
object-oriented technologies.
www.ibm.com/software/rational/uml
This is the UML resource page for IBM
Rational—the successor to the Rational Software Corporation (the company that
created the UML).
Recommended Readings
The following books provide
information about object-oriented design with the UML:
Ambler, S. The Object Primer: Agile
Model-Driven Development with UML 2.0, Third Edition. New York: Cambridge
University Press, 2005.
Arlow, J., and I. Neustadt. UML and the
Unified Process: Practical Object-Oriented Analysis and Design, Second
Edition. Boston: Addison-Wesley Professional, 2006.
Fowler, M. UML Distilled, Third
Edition: A Brief Guide to the Standard Object Modeling Language. Boston:
Addison-Wesley Professional, 2004.
Rumbaugh, J., I. Jacobson and G. Booch. The Unified Modeling Language User Guide, Second
Edition. Boston: Addison-Wesley Professional, 2006.
| 1.1 |
List three examples of real-world
objects that we did not mention. For each object, list several attributes and
behaviors. |
| 1.2 |
Pseudocode is __________.
-
-
a programming language used to display UML
diagrams
-
an informal means of expressing program logic
-
a graphical representation scheme for modeling object-oriented
systems |
| 1.3 |
The UML is used primarily to __________.
-
test object-oriented systems
-
design object-oriented systems
-
implement object-oriented systems
-
|
Answers to Section 1.10 Self-Review
Exercises
| 1.1 |
[Note:
Answers may vary.] a) A television's attributes include the size of the screen,
the number of colors it can display, its current channel and its current volume.
A television turns on and off, changes channels, displays video and plays
sounds. b) A coffee maker's attributes include the maximum volume of water it
can hold, the time required to brew a pot of coffee and the temperature of the
heating plate under the coffee pot. A coffee maker turns on and off, brews
coffee and heats coffee. c) A turtle's attributes include its age, the size of
its shell and its weight. A turtle walks, retreats into its shell, emerges from
its shell and eats vegetation. |
| 1.2 |
c. |
| 1.3 |
b. |