Objects First


Other Object Oriented Languages

Using the design style that we've been following in this course, conversion to other object-oriented languages is mainly a matter of learning some new syntax, although there are some significant semantic features of other OO languages that you will need to learn. Since C is a relatively "low-level" language, the "object oriented" languages generally try to make things a little easier for the programmer and do things for you that you had to write out explicitly in C. For example, in both C++ and Java, a method of a class is assumed to operate on an object of the class and it's not necessary to provide the object on which the method is operating in the formal parameter list. Compare the Point class implemented in Java with it's C counterpart.
Compare the Java:
   public double XCoord() {
      return x;
      }
In Java, this is called with:
   Point p;
   p = new Point( a, b );
   x = p.XCoord();
Note how the object on which the method operates precedes the name of the method.

Java, with formal support for OO design, provides a new keyword which precedes the constructor. The name of the constructor is also the same as the name of the class. (This is a requirement in Java - as distinct from the convention that we adopted in C.)

Within the implementation of the method, attributes, such as x in this example, can be referenced directly. Java "understands" the connection between an object and its attributes, so there isn't the need to put them all into a struct as we do in C.

with the C:
   double XCoord( Point p ) {
      return p->x;
      }
In C, we provided the point on which the method operates as the argument of the function:
    Point p;
    p = ConsPoint( a, b );
    x = XCoord( p );
In C, without formal support for the OO design methodology, you must specify the object on which the method operates as one of the function parameters.

A more elaborate example in Java: the Histogram class.
Example of a Java program that uses the Histogram class.
We're indebted to Sofie Hon for these examples!

C++

The international standard, ISO/IEC 14882:1998 (C++), was published on October 1, 1998. The ISO printing of the C++ standard is 732 pages in length, compared to 511 pages for Ada95 - Ada was considered to be a very large language when it was designed!

Back to the Table of Contents
© John Morris, 1998