An object has an interface | CodeGuru

An object has an interface

Bruce Eckel’s Thinking in Java Contents | Prev | Next Aristotle 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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 1, 2001
3 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Aristotle


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


class

that introduces a new type into a program (thus


class

and


type

are often used synonymously


[3]

).

Simula,


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.

So,


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.

Once


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


problem
space

(the place where the problem actually exists) and the


solution
space

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

But


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


interface

,


and the type is what determines the interface. The idea of type being


equivalent to interface is fundamental in object-oriented programming.

A


simple example might be a representation of a light bulb:

Light lt = new Light();
lt.on();

The


name of the type/class is


Light

,


and the requests that you can make of a


Light

object are to turn it on, turn it off, make it brighter or make it dimmer. You


create a “handle” for a


Light

simply


by declaring a name (


lt

)


for that identifier, and you make an object of type


Light

with the


new

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


objects.



[3]

Some people make a distinction, stating that type determines the interface


while class is a particular implementation of that interface.

Contents

|

Prev

|

Next
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.