Software Engineering Case Study: Introduction to Object Technology and the UML

Software Engineering Case Study Introduction to Object Technology and the UML

Now we begin our early introduction to object orientation, a natural way of thinking about the world and writing computer programs. Chapter 1, 39 and 11 each 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, the only required section of the case study, we introduce basic object-oriented concepts and terminology. The optional sections in Chapters 39 and 11 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 39

The "Software Engineering Case Study" sections at the ends of Chapters 9 and 11 modify and enhance the design presented in Chapters 38. Appendix J 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 will experience a solid introduction to object-oriented design with the UML. Also, you will sharpen your code-reading skills by touring a complete, straightforward 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 objectspeople, animals, plants, cars, planes, buildings, computers 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 sensethey 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 will study the kinds of attributes and behaviors that software objects have.

Humans learn about 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 characteristicscars, 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 "convertible" class 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 processnamely, 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, or a teenager text messages a friend to meet at the movies), 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 objectsan 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 implementedimplementation details are hidden within the objects themselves. You can drive a car effectively, for instance, without knowing the details of how engines, transmissions, brakes and exhaust systems work internallyas long as you know how to use the accelerator pedal, the brake pedal, the steering wheel and so on. Information hiding, as you will 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 conveniently implement an object-oriented design as a working software system. 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 methods (C#'s equivalent of C's functions) that implement operations, and data that implements attributes.

Classes, Data Members and Methods

C# programmers concentrate on creating their own user-defined types called classes. Each class contains data as well as the set of methods that manipulate the data and provide services to clients (i.e., other classes that use the class). The data components of a class are called attributes, or fields. For example, a bank account class might include an account number and a balance. The operation components of a class are called methods. For example, a bank account class might include methods to make a deposit (increase the balance), make a withdrawal (decrease the balance) and inquire what the current balance is. The programmer uses 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 housesa class is a "plan" for building objects 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, but you can cook meals in the kitchen of a house. You cannot sleep in the bedroom of a blueprint, but 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 often are 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 often say that the three most important factors affecting the future of software development are "reuse, reuse and reuse."

Software Engineering Observation 1 1

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 will 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)

Soon you will be writing programs in C#. How will you create the code for your programs? Perhaps, like many beginning programmers, you will simply turn on your computer and start typing. This approach may work for small programs (like the ones we present in the early chapters of the book), but what if you were asked to create a software system to control thousands of automated teller machines for a major bank? Or what if you were asked to work as part of a team of 1,000 software developers building the next generation of the U.S. air traffic control system? For projects so large and complex, you could not simply sit down and start writing programs.

To create the best solutions, you should follow a detailed process for analyzing your project's requirements (i.e., determining what your system is supposed to do) and developing a design that satisfies them (i.e., deciding how your system should do it). Ideally, you would go through this process and carefully review the design (and 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 object-oriented analysis and design (OOAD). Experienced programmers know that proper analysis and design can save many hours by helping avoid an ill-planned system development approach that has to be abandoned partway through its implementation, possibly wasting considerable time, money and effort.

OOAD is the generic term for the process of analyzing a problem and developing an approach for solving it. Small problems like the ones discussed in the first few chapters of this book do not require an exhaustive OOAD process. It may be sufficient, before we begin writing C# code, to write pseudocodean informal text-based means of expressing program logic. It is not actually a programming language, but you can use it as a kind of outline to guide you as you write your code. We introduce pseudocode in Chapter 5.

As problems and the groups of people solving them increase in size, OOAD quickly becomes more appropriate than pseudocode. Ideally, a group should agree on a strictly defined process for solving its 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 methodologistsincluding Grady Booch, James Rumbaugh and Ivar Jacobsonindividually 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 (i.e., determining what a proposed system is supposed to do) and design (i.e., determining how a proposed system should be implemented to do what it is supposed to do).

By the early 1990s, different organizations 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 process 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 corporationsamong them HP, IBM, Microsoft, Oracle and Rational Softwarehad already recognized the need for a common modeling language. In response to the OMG's request for proposals, these companies formed the UML Partnersthe 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. We present the recently adopted UML 2 terminology and notation throughout this book.

What is the UML?

The Unified Modeling Language (UML) is 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, many of which we discuss throughout our ATM case study) to model their systems. We use several popular types of UML diagrams in this book.

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.

The UML is a feature-rich graphical language. In our subsequent (and optional) "Software Engineering Case Study" sections on developing the software for an automated teller machine (ATM), we present a simple, concise subset of these features. We then use this subset to guide you through a first design experience with the UML. We will use some C# notations in our UML diagrams to avoid confusion and improve clarity. In industry practice, especially with UML tools that automatically generate code (a nice feature of many UML tools), you would probably adhere more closely to UML keywords and UML naming conventions for attributes and operations.

This case study was carefully developed under the guidance of distinguished academic and professional reviewers. We sincerely hope you enjoy working through it. If you have any questions, please communicate with us at deitel@deitel.com. We will respond promptly.

Internet and Web UML Resources

For more information about the UML, refer to the following Web sites. For additional UML sites, please refer to the Internet and Web resources listed at the end of Section 3.10.

www.uml.org

This UML resource site 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 Rationalthe successor to the Rational Software Corporation (the company that created the UML).

Recommended Readings

Many books on the UML have been published. The following recommended books provide information about object-oriented design with the UML.

 

• Arlow, J., and I. Neustadt. UML and the Unified Process: Practical Object-Oriented Analysis and Design, Second Edition. London: Addison-Wesley, 2005.

• Fowler, M. UML Distilled, Third Edition: Applying the Standard Object Modeling Language. Boston: Addison-Wesley, 2004.

• Rumbaugh, J., I. Jacobson, and G. Booch. The Unified Modeling Language User Guide, Second Edition. Upper Saddle River, NJ: Addison-Wesley, 2005.

For additional books on the UML, please refer to the recommended readings listed at the end of Section 3.10, or visit www.amazon.com, www.bn.com and www.informIT.com. IBM Rational, formerly Rational Software Corporation, also provides a recommended-reading list for UML books at www.ibm.com/software/rational/info/technical/books.jsp.

Section 1.17 Self-Review Exercises

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 __________.

  1. another term for OOAD
  2. a programming language used to display UML diagrams
  3. an informal means of expressing program logic
  4. a graphical representation scheme for modeling object-oriented systems

 
1.3

The UML is used primarily to __________.

  1. test object-oriented systems
  2. design object-oriented systems
  3. implement object-oriented systems
  4. Both a and b

Answers to Section 1.17 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, and its current channel and 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 crawls, retreats into its shell, emerges from its shell and eats vegetation.

1.2

c.

1.3

b.

Категории