Introduction to Object Orientation

Under Construction

The terminology I use here is the one I learnt on the Open University's M868 Object-Oriented Software Technology course, which included Smalltalk. There are variations out there.

We are all used to using objects. They are the abstract names we use for the things that we are interested in - such as cars, trees, animals, vehicles, employees, plants, bank accounts. We choose the level of abstraction that suits the task in hand. So, an individual may go out to buy a car, but the vehicle licensing authority is interested in all kinds of vehicles, not just cars. Because objects tend to change less often that the details of the procedures we want to perform on them, it can be useful to associate our procedures with the objects, and this is what is done in object orientation. In object oriented programming, an object is a set of data items plus all the procedures that operate on them. So, the object employee would have procedures such as hire employee, pay employee and fire employee associated with it.

The data, and a lot of the detail of the procedures, are hidden from view within the object, with only interface procedures being visible. This is called encapsulation. That way, if for example the format of the registration number of car objects changes, the internal code of the car object can change, whilst all of the applications that use the car object need not. They just need to call the object's interface procedures (such as "record car registration") as normal, with the car's registration number in the correct format. The set of interface procedures which an object supports is called the protocol.

Each individual example of an object, for example, my one and only car, is called an object instance, or object for short. The data items are called instance variables. They are characteristics of the class. Instances can only be updated by the procedures provided in the class definition. We don't write procedures for single instances; we write them for a whole class of objects such as the "car" class, and define the general characteristics of the class. A class is a template used to create instances of the class.

In Smalltalk the procedures are called instance methods, or just methods. The parameters passed via the procedures, such as car registration number, are called arguments. Invoking a procedure is called sending a message. The method name follows after the object instance for which it is invoked, for instance,
mycar picture
causes the method picture to display a picture of the object mycar. As no argument is passed, this is called a unary message. mycar is called the receiver object, which is expected to whatever is described by the message selector, or selector for short (picture) assuming that it has such a method defined for it. The whole line of code is called an expression. The method is the operation supported by the object and defined by the class, whilst the selector forms a message requiring an object to invoke the method with that name.

If a message includes arguments, it is called a keyword expression, for example:
mycar paint: gold
might be used to denote that the car's colour had changed. The colon denotes that an argument follows.Messages can consist of more than one keyword, for example, the method setServiceType:setServiceDate: is invoked to set the instance variables holding the type and date of the next service due as follows:
mycar setServiceType: 'full' setServiceDate: '10 March 2002'

When you send a message to an object, you get an object back. The receiver is said to with an object. This could be the result of processing by the message, such as the picture requested earlier, or it maybe the receiver object itself - for example, mycar with colour set to gold or service date and type set to '10 March 2002' and 'full', respectively.

To be continued.

Back to top     Home     Serious Stuff

© 2002. Copyright Sue Nethercott.