An object has an interface

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Bruce Eckel’s Thinking in Java Contents | Prev | Next

was probably the first to begin a careful study of the concept of type. He was
known to speak of “the class of fishes and the class of birds.” The
concept that all objects, while being unique, are also part of a set of objects
that have characteristics and behaviors in common was directly used in the
first object-oriented language, Simula-67, with its fundamental keyword
that introduces a new type into a program (thus
are often used synonymously

as its name implies, was created for developing simulations such as the classic
“bank teller problem.” In this, you have a bunch of tellers,
customers, accounts, transactions, etc. The members (elements) of each class
share some commonality: every account has a balance, every teller can accept a
deposit, etc. At the same time, each member has its own state; each account has
a different balance, each teller has a name. Thus the tellers, customers,
accounts, transactions, etc. can each be represented with a unique entity in
the computer program. This entity is the object, and each object belongs to a
particular class that defines its characteristics and behaviors.

although what we really do in object-oriented programming is create new data
types, virtually all object-oriented programming languages use the
“class” keyword. When you see the word “type” think
“class” and vice versa.

a type is established, you can make as many objects of that type as you like,
and then manipulate those objects as the elements that exist in the problem you
are trying to solve. Indeed, one of the challenges of object-oriented
programming is to create a one-to-one mapping between the elements in the

(the place where the problem actually exists) and the

(the place where you’re modeling that problem, such as a computer).

how do you get an object to do useful work for you? There must be a way to make
a request of that object so it will do something, such as complete a
transaction, draw something on the screen or turn on a switch. And each object
can satisfy only certain requests. The requests you can make of an object are
defined by its
and the type is what determines the interface. The idea of type being
equivalent to interface is fundamental in object-oriented programming.

simple example might be a representation of a light bulb:

Light lt = new Light();

name of the type/class is
and the requests that you can make of a
object are to turn it on, turn it off, make it brighter or make it dimmer. You
create a “handle” for a
by declaring a name (
for that identifier, and you make an object of type
with the
keyword, assigning it to the handle with the
sign. To send a message to the object, you state the handle name and connect it
to the message name with a period (dot). From the standpoint of the user of a
pre-defined class, that’s pretty much all there is to programming with

Some people make a distinction, stating that type determines the interface
while class is a particular implementation of that interface.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read