Object Oriented Programming in Script/Object Oriented Terminology

From SCI Wiki
Jump to navigationJump to search

Official SCI Documentation

Chapter: 1 | 2 | 3 | 4 | 5 | 6 | Index


Object Oriented Terminology

Author: Jeff Stephenson

Date: 4 April 1988

 


Object Oriented Terminology


Property

Properties are data associated with an object. A door object might have such properties as the room number into which it opens, its state (open or closed), and its position on the screen.


Method

A method is a procedure which is internal to an object or class. A door object might have a method open which causes the door to change state from closed to open.


Message

Methods of an object are invoked by sending the object messages. In Script a message is sent to an object by enclosing the object name, then the message, in parenthesis (much like a procedure call):

Code:
(doorToCloset open:)

sends the open: message to the object doorToCloset.


Selector

Selectors are used in messages to indicate the method which is to be invoked. The symbol open: in the above example of messaging is the selector for the open method.


Object

An object is a collection of properties and methods bundled together, and should be considered to be a distinct entity (hence the use of the word 'object').


Class

A class is a 'generic' object of a certain type. It has no real existence of its own, but provides the default methods and property values to those objects which are instances (see below) of it. Classes may have sub-classes, which are more specific types of a class (for example, the class SlidingDoor is a sub-class of the class Door) and super-classes, which are generalizations of the class (the class Opening might be a super-class of the class Door).


Instance

An instance of a class is a 'concrete' object which has the properties and methods of the class, but whose properties are distinctly its own. For example the object doorToCloset is an instance of the class Door which is different from the object doorToPatio, another instance of class Door. Changing the property values of an instance (object) of a class will not affect the property values of other instances of the class.


Inheritance

Inheritance is one of the most important concepts in OOP, and is responsible for much of its power. A sub-class inherits all the methods and properties of its super-class, then goes on to add its own distinct properties and methods, or to modify an inherited method from its super-class. We might define the class ElevatorDoor as a sub- class of the class Door. It would thus inherit the properties of Door but would add a property to tell whether the light associated with the door is on or off. It would also inherit Door's methods, but would modify the open method to not only change the state of the ElevatorDoor to open, but also to change the state of the light property to on. All other methods work just the same as for the Door class.


Self

Often, an object needs to invoke one of its own methods, without really knowing who it is (it may be executing code inherited from its super- class). This is done by sending a message to the object self, which is always the object which invoked the current method.


Super

An important factor in using inheritance to define new methods is being able to get access to the super-class's code for a method within the newly defined method. The class super is provided for this purpose -- sending a message to class super invokes the method within the super- class of self, rather than the method within self. Thus, the open method for the class ElevatorDoor might contain the code

Code:
(super open:)
(= lightState on)

which calls upon the open method of the class Door to do its stuff, then sets the light state to on.


A Note on Naming

There are a number of conventions which are normally (but not universally) followed in naming things in object oriented programming. Properties, being data, usually have names which are nouns; methods, being actions on data, usually have names which are verbs; classes and instances, which may represent either concrete objects or actions, may have either nouns or verbs as names.

The first letter of property, method, and instance names is lowercase, whereas the first letter of class name is uppercase. In both types of names, succeeding words in the names are set off in the name by capitalizing the first letter of the word, e.g. AutomaticDoor or elevatorDoor.

 

Notes


 

Table of Contents

 

< Previous: Object Oriented Programming Next: Classes >