Small Business Resources, Business Advice and Forms from AllBusiness.com
 
Get a Report on this industry

Object Oriented Programming

The best tips and advice from our vast library of articles, videos, and business tools
Free Industry Resources

Newly Added Articles

 

How to Turn Your Business Dream into a Successful Reality

Napa Valley business owners tell Sumer Morenz of D&B Digital TV how they turned passion into bottom-line success.

Franchise Finder

franchise_sb_icon
Find your perfect franchise
Choose your location and industry and we'll show you the most relevant franchises.
Industry:
Location:

Business Glossary
icon - industry associations

Definitions for: object-oriented programming
object-oriented programming

a programming methodology in which the programmer can define not only data types, but also methods that are automatically associated with them.Ageneral type of an object is called a class. Once a class has been defined, specific instances of that class can be created.

The same name can be given to different procedures that do corresponding things to different types; this is called polymorphism. For example, there could be a "draw" procedure for circles and another for rectangles.

Some uses for object-oriented programming include the following:

  1. Graphical objects. A program that manipulates lines, circles, rectangles, and the like can have a separate "draw" and "move" procedure for each of these types.
  2. Mathematical objects. In order to work with vectors, matrices, or other special mathematical objects, the programmer has to define not only data structures for these objects, but also operations such as addition, inversion, or finding a determinant.
  3. Input-output devices. The procedure to draw a line might be quite different on a printer or plotter than on the screen. Object-oriented programming provides a simple way to ensure that the right procedure is used on each device.
  4. Simulation. In a program that simulates traffic flow, for example, cars, trucks, and buses might be types of objects, each with its own procedures for responding to red lights, obstructions in the road, and so forth. This, in fact, is what object-oriented programming was invented for. The first object-oriented programming language was Simula, introduced in 1967.
  5. Reusable software components. Object-oriented programming provides a powerfulway to build and use components out of which programs can be built. For example, a programmer might use a predefined object class such as "sorted list" (a list that automatically keeps itself in order) rather than having to write procedures to create and sort a list.

Here is an example of object-oriented programming in Java. Imagine a program that manipulates points, lines, and circles. A point consists of a location plus a procedure to display it (just draw a dot). So the programmer defines a class called pointtype as follows:

The class pointtype is defined to include two integer variables (x and y) and one method (draw). (The class also would include a constructor - a method called when a new object of that class is created.)

Now variables of type pointtype can be declared, for example:


pointtype: a,b;

Here the objects a and b each contain an x and a y field; x and y are called instance variables. In addition, a and b are associated with the draw procedure. Here's an example of how to use them:


a.x = 100;
a.y = 150:
a.draw(g);

This sets the x and y fields of a to 100 and 150, respectively, and then calls the draw procedure that is associated with a (namely pointtype.draw). (The g stands for graphics.)

Now let's handle circles. A circle is like a point except that in addition to x and y, it has a diameter. Also, its draw method is different. We can define circletype as another type that includes a pointtype, and it adds an instance variable called diameter and substitutes a different draw method. Here's how it's done:

Your program would create a new object of class circletype (call it c), define values for the variables, and then call the method circletype.draw to display the circle on the screen. See the book's web page, www.termbook.com, for an example.

It is important to remember that instance variables belong to individual objects such as a, b, and c, but methods (procedures) belong to object types (classes). One advantage of object-oriented programming is that it automatically associates the right procedures with each object: c.draw uses the circle draw procedure because object c is a circle, but a.draw uses the point draw procedure because object a is a point.

The act of calling one of an object's methods is sometimes described as "sending a message" to the object (e.g., c.draw "sends a message" to c saying "drawyourself").All object-oriented programming systems allow one class to inherit from another, so the properties of one class can automatically be used by another class. For example, there is a standard Java class called Applet which contains the code needed to display an applet on the web. When you write your own applet, it will inherit from (extend) this class, so you don't need to recreate that code yourself.

Copyright © 2006, 2003, 2000, 1998, 1996, 1995, 1992, 1989, 1986 by Barron's Educational Series, Inc. Reprinted by arrangement with Publisher.

Search the Business Glossary: