Introduction to Objects, UML, and Java
This book is about object-oriented (OO) 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 processanalysis of the problem, design of a solution, coding, and long-term maintenance. Object-oriented development can make any 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 (Unified Modeling Language), a modeling tool that aids 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 to changing 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.
Object-oriented programming works much better when it is used together with an object-oriented analysis and design (OOAD) process. 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 (see Figure Figure 1.1). An OO program in
Figure 1.1 A randomly planned house
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 listvirtually anything. One way to think of an object is as a black box with some buttons and lights (see Figure 1.2). This could be a TV, a car, whatever. To use the object, you need to know what the buttons do, whichones 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 it can provide information about its current state. The internal repre-sentation, algorithms, and data structures are hidden from the outside world.
Figure 1.2 A black box
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 it can provide information about its current state. The internal representation, algorithms, and data structures are hidden from the outside world.
In the simplest terms, designing an OO system consists of identifying which 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 lead 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 important, 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 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.