MSc-IT Study Material
January 2011 Edition

Computer Science Department, University of Cape Town
| MIT Notes Home | Edition Home |

Operations

In the last section we considered attributes, which say something about what a class is. Operations say what a class does (or can have done to it). When you have fully specified the attributes and operations of a class, then you have specified that class completely (some experts would say that one must specify the class's constraints as well, but that is largely beyond the scope of this course).

For example, the Clock class may have the operation display time. This is something that a clock does. It is not an attribute of class clock, because it does not tell us anything about objects of class clock that we do not already know.

At the design stage, we tend to assume that all of a class's operations are accessible to other classes, that is, classes can communicate by invoking each others operations. This is called message passing. As design progresses, we usually find that new operations have to be added that are private to that class, because they are only concerned with internal operation of the class. Remember that classes should be self-contained, and should expose as little as possible of their internal workings.

In the same way that attributes are formalised in object-oriented design, beyond what is true of classification in general, operations are also formalised. An operation has a name, a parameter list, and a return value, much like a function. The parameter list is (essentially) the data elements that will be supplied to the operation. The return value is a piece of data that can be returned to the object that invoked the operation. These issues are not very important in the early stages of design (we may only know the name of the operation), but become important as the design is translated into a program. Note that an operation has access to the object's attributes, and can read or write them, but normally has no access to the attributes of other objects.

Terminology

Other terms for operation include member function, class function, and method. Java programmers tend to use the term method.