TOC PREV NEXT INDEX

Put your logo here!

The Essence of Object Oriented Programming with Java and UML


Chapter 1

Objects, UML, and Java

 

Introduction

This book is about object-oriented software development. Writing real object-oriented programs that are used by real people is more than slapping down a few lines of code in Java (or C++, Eiffel, or any other object-oriented programming language). Ultimately, object-oriented software development includes the complete process - analysis of the problem, design of a solution, coding, and finally long-term maintenance. Object-oriented development can make any size program better - from a small web based application to a full-blown business critical software system.

Object orientation has the potential for building great software, but only if it is used as part of a complete process. Today, there are small, agile development methodologies suitable for teams of two to ten or so programmers, as well as large scale methodologies for huge projects. Most of these development methodologies use or can benefit from the UML, a modelling tool that can aid the design of any OO system. But before you can understand and use any of these methodologies, you need to move beyond merely getting a program to work, and change your thinking to be object-oriented.

It has been said that any programming language can be used to write object-oriented programs (and it has been done with C), but a true OO programming language makes it a lot easier. Just because you use an OO programming language, your programs are not necessarily object-oriented.

Figure 1-1.
A Randomly Planned House

Object-oriented programming works much better when it is used together with an object-oriented analysis and design process (OOAD). Trying to write an OO program without first going through the analysis and design steps is like trying to build a house without first analyzing the requirements of the house, designing it, and producing a set of blueprints. You might end up with a roof over your head, but the rooms would likely be scattered all over the place, some rooms might be missing, and the whole thing would probably come tumbling down on your head during the first storm (Figure 1-1). An OO program in any programming language written without at least some OOAD might seem to work, but it is much more likely to be full of bugs, and break when you make the first modification.

Object Orientation

Objects are the heart of object orientation. An object is a representation of almost anything you need to model in a program. An object can be a model of an employee, a representation of a sensor, a window in a user interface, a data structure such as a list, virtually anything. One way to think of an object is as a black box with some buttons and lights (Figure 1-2). This could be a TV, a car, whatever. To use the object, you need to know what the buttons do, which ones you need to press to get the object to do what you need, and what the lights mean about the status of the object. The details of how the box is put together inside are irrelevant while you are using the box. What is important is that the object carries out its functions and responsibilities correctly. A software object is not much different. It has well-defined methods for interacting with the outside world, and can provide information about its current state. The internal representation, algorithms, and data structures are hidden from the outside world.

Figure 1-2.
A Black Box

In the simplest terms, designing an OO system consists of identifying what objects the system contains, the behaviors and responsibilities of those objects, and how the objects interact with each other. OO can produce elegant, easy to understand designs, which in turn leads to elegant and easy to understand programs. Individual objects can often be implemented and debugged independently. Libraries of existing objects can be easily reused and adapted to new designs. Most importantly, a good OO program is easy to modify, and resistant to the introduction of bugs during program modification and maintenance.

Object-oriented development is a major advance for software development. Although it may not be a magic bullet that solves all the problems associated with producing software, it is really better than other methodologies. While development methodologies such as structured design and programming have many valid points, many which carry over and are used for OO development, object-oriented designs are inherently easier to design and maintain over time.

Object-Oriented Languages

There are several object-oriented programming languages available to choose from, including Smalltalk, Eiffel, C++, Objective C, Objective Pascal, Java, Ada, and even a version of Lisp. There are two clear marketplace winners, C++ and Java.

Today, Java is the emerging object-oriented language of choice for many programmers and software projects. One of the main reasons for Java's emergence is the World Wide Web, and Java's ability to run web applets directly on any computer or operating system with a web browser. Another reason is that Java is an excellent programming language. It is a small, well-designed language that can be used for not just web applets, but full-blown programs on almost any computer available today. Java was somewhat hampered in its early days because of its speed, but this is really no longer an issue. Because it is such a good language, Java has been widely adopted as the main language used to teach computer science at colleges and universities all over the world. In the whole history of computer science and programming, this is the first time that the same programming language has been popular as both a teaching language and a language used for real world programs.

C++ is also a widely used programming language. It is still the principle language used for the core applications (such as spread sheets and word processors) used on most computers today. One of the main reasons is that C++ was derived from C, and thus has a heritage of being able to do real things on real systems. There is compatibility with existing C code. One of the problems with C++, however, is that it has grown into a large and complicated language. It is difficult to achieve competence in the full language.

This book is mostly about object-oriented programming. Primarily, that means it will focus on general principals of object-oriented programming that apply to any programming language. But this book will also show how to translate object-oriented designs to real programs using Java. The focus will be on how to use the capabilities of the Java language to implement OO designs. It is not a tutorial on learning Java. We assume that you've already learned the Java basics. Now you are ready to learn about objects, and how to use Java to write better programs.

Object-Oriented Design and the UML

There are several different object-oriented development methodologies in use today. Each has its strengths and weaknesses. The older, more traditional methodologies are often called "heavyweight" methodologies, and are most useful for large software projects involving tens or even hundreds of programmers over years of development effort. The newer methodologies are called "lightweight" or "agile" methodologies, and are more appropriate for smaller projects. Many of these are quite new and still being standardized as this book was being written.

Design and development methodologies have always needed a graphical notation to express the designs. In the past, one of the major problems has been that each major methodology has had its own graphical notation. This has all changed with the emergence of the UML (Unified Modeling Language) as the standard notation. Any of the current design methodologies, heavyweight or agile, use or can benefit from the UML.

The UML originated in the mid-1990's from the efforts of James Rumbaugh, Ivar Jacobson, and Grady Booch (The Three Amigos). There is a standard specification of the UML coordinated by the Object Management Group (www.omg.org). OMG is an industry sponsored organization devoted to supporting vendor-neutral standards for the object-oriented development community. The UML has become the de facto standard object-oriented notation.

The UML is designed for discussing object-oriented design. Its ability to show objects and object relationships is especially useful, and will be used in examples throughout this book. The various features of the UML will be introduced as needed.

The Payoff of Objects

Object orientation can lead to big payoffs in the software development game. An object-oriented design is likely to be simple and easy to understand. Once designed, you can often implement and test the individual objects separately. Once finished, each object tends to be robust and bug free. As you make changes to the system, existing objects continue to work. And as you improve existing objects, their interface to the world stays the same, so the whole system continues to work. It is this ease of change and robustness that really makes OO development different, and well worth the effort.

Chapter Summary


TOC PREV NEXT INDEX

The Essence of Object-Oriented Programming with Java and UML (DRAFT)

Copyright © 2001 by Addison-Wesley

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. You may view this document on a web browser, but you must not mirror or make local copies.