Introduction to Objects:
Guides | Language > OOP

Introduction to Objects

Introduction to objects and messages

Objects and Messages

The SuperCollider language is an object oriented language. All entities in the language are objects. An object is something that has data, representing the object's state, and a set of operations that can be performed on the object. All objects are instances of some class which describes the structure of the object and its operations. Objects in SuperCollider include numbers, character strings, object collections, unit generators, wave samples, points, rectangles, graphical windows, graphical buttons, sliders and much more.

Operations upon objects are invoked by messages. A message is a request for an object, called the receiver, to perform one of its operations. The means by which the operation is performed is determined by the object's class. Objects of different classes may implement the same message in different ways, each appropriate to the class of the object. For example all objects understand the value message. Many objects simply return themselves in response to value, but other objects such as functions and streams first evaluate themselves and return the result of that evaluation. The ability for different objects to react differently to the same message is known as polymorphism and is perhaps the most important concept in object oriented programming since it allows the object's behaviour to be abstract from the point of view of the user of the object (the client).

The set of messages to which an object responds to is known as its interface. A set of messages that implement a specific kind behaviour is known as a protocol. An object's interface may include several protocols which allow the object to interact in several different contexts. For example all objects implement the 'dependancy' protocol which allow the object to notify other dependant objects that the object has changed and that the dependant should do any necessary action to update itself.

An object's internal state may only be changed by sending it messages. This allows the implementation of the object to be hidden from the client. The advantage to this is that the client does not depend on the object's implementation and that that implementation can be changed without having to change the client.

See Messages for more information about messages.

Classes, Instance Variables, Methods

An object's class contains the description of the object's data and operations. A class also describes how to create an object which is an instance of that class.

An object's data is contained in its instance variables. These are named variables that describe the object's state. The values of the instance variables are themselves objects. For example, instances of class Point have instance variables named 'x' and 'y' which contain the coordinate values of the Point.

An instance variable is only directly accessible from within the class itself. The author of a class may decide to expose instance variable access to clients by adding getter and/or setter messages to the class.

A method is a description of the operations necessary to implement a message for a particular class. The methods in a class tell how to implement messages sent to its instances. A class contains a method definition for each message to which its instances respond. Methods generally fall into several categories. Some methods inquire about some property of the receiver. Others ask the receiver to make some change to its internal state. Still others may ask the receiver to return some computed value.

See Classes for more details about instance and class variables and methods.

Summary of Terminology

something that has data, representing the object's state, and a set of operations that can be performed on the object.
a request for an object to perform an operation.
the object to which a message is sent.
a description of the state and behaviour of a set of objects.
the set of messages to which an object responds.
a set of messages that implement a specific kind of behaviour.
the ability for different kinds of objects to respond differently to the same message.
a description of the operations necessary to implement a message for a particular class.
one of the objects described by a class.
instance variable
a part of an object's internal state