3 Introducing Objects and Classes
This chapter has introduced the ideas of object and class. An object combines variables and methods into a single unit, giving a public interface and an encapsulated private representation. A class is used to define the implementation of an object and, in doing so, introduces a new type. Objects interact by calling each others' methods and those methods are dynamically bound, so a calling object is only concerned with the public interface presented by an object and not its implementation.
We now have the basic ideas of object-oriented programming in place and can finish this chapter by formally make the following definitions:
- A Class defines a user-defined data type, creating a new type and providing the implementation for objects of that class. Classes specify a public interface and a private implementation.
- An Object is an instance of a class (and only one class). From the outside an object can only be used according to the public interface defined by its class.
- A Method is a procedure or operation defined by a class and used by an object.
- An Instance Variable is a variable that is defined by a class and is part of an object of that class.
- An object is created by instantiation of a particular class and the object can be referenced by a variable of the class type.
- The state of an object is determined by the values of its instance variables. As the methods of an object are called, the object changes from one state to the next. An object should always be in a valid state.
Copyright © 1997 Russel Winder and Graham Roberts
Last updated: 6 Oct 1997