380 Object-Based Programming Chapter 8 (Com web hosting) Let us briefly

380 Object-Based Programming Chapter 8 Let us briefly review some key concepts and terminology of object orientation. OOP encapsulates data (attributes) and methods (behaviors) into objects; the data and methods of an object are intimately tied together. Objects have the property of information hiding. This means that although objects might know how to communicate with one another across well-defined interfaces, objects normally are not allowed to know how other objects are implemented implementation details are hidden within the objects themselves. Surely it is possible to drive a car effectively without knowing the details of how engines, transmissions and exhaust systems work internally. We will see why information hiding is so crucial to good software engineering. In C and other procedural programming languages, programming tends to be action- oriented. In Java, programming is object-oriented. In C, the unit of programming is the function (called methods in Java). In Java, the unit of programming is the class from which objects are eventually instantiated (i.e., created). Functions do not disappear in Java; rather, they are encapsulated as methods with the data they process within the walls of classes. C programmers concentrate on writing functions. Groups of actions that perform some task are formed into functions, and functions are grouped 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-requirements document help the C programmer determine the set of functions that will work together to implement the system. Java programmers concentrate on creating their own user-defined types called classes. Classes are also referred to as programmer-defined types. Each class contains data as well as the set of methods that manipulate the data. The data components of a class are called instance variables (these are called data members in C++). Just as an instance of a built-in type such as int is called a variable, an instance of a user-defined type (i.e., a class) is called an object. The focus of attention in Java is on objects rather than methods. The nouns in a system-requirements document help the Java programmer determine an initial set of classes with which to begin the design process. These classes are then used to instantiate objects that will work together to implement the system. This chapter explains how to create and use objects, a subject called object-based programming (OBP). Chapter 9 introduces inheritance and polymorphism two key technologies that enable true object-oriented programming (OOP). Although inheritance is not discussed in detail until Chapter 9, inheritance is part of every Java class definition. Performance Tip 8.1 When passing an object to a method in Java, only a reference to the object is passed, not a copy of a possibly large object (as would be the case in a pass by value). Software Engineering Observation 8.1 It is important to write programs that are understandable and easy to maintain. Change is the rule rather than the exception. Programmers should anticipate their code s being modified. As we will see, classes facilitate program modifiability. 8.2 Implementing a Time Abstract Data Type with a Class The next example consists of two classes Time1 (Fig. 8.1) and TimeTest (Fig. 8.2). Class Time1 is defined in file Time1.java. Class TimeTest is defined in a separate file called TimeTest.java. It is important to note that these classes must be defined in Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

Leave a Reply