A Brief Introduction to Object-Oriented Design

How Use Abstraction, Inheritance and Instantiation in Java Classes

A Brief Introduction to Object-Oriented Design - Mark Alexander Bain
A Brief Introduction to Object-Oriented Design - Mark Alexander Bain
Object-oriented design is an important technique because it enables the programmer abstract information from existing objects and for classes to inherit characteristics

Both object-oriented programming and Java are important to every level of programmer as shown by the release of Eurotech Inc's Helios platform (see Reuters: Eurotech Launches Helios(TM) Platform, Industry's First Programmable Edge Controller).

The company's president and CTO, Arlen Nipper, said "Combining our configurable hardware platform, Helios, with the ESF middleware gives Eurotech customers the greatest range of flexibility, in I/O options, connectivity choices, and object-oriented programming".

The middleware framework itself is Java based. This, of course, raises an important question for any new programmers. How do they start object-oriented design, and how do turn an object-oriented design into a Java application? It is, therefore, worth considering the basics of object-oriented programming.

A Universe Full of Objects

An object is simply something that exists in the universe. Take, for instance, the Kawasaki Ninja ZX-10R. The Kawasaki Ninja ZX-10R:

  • has an 899cc, four stroke engine with a DOHC (Double Over Head Cam)
  • has a 3.7 imperial gallon or 4.5 US gallon fuel tank
  • accelerates from 0 to 60 mph in 2.9 seconds
  • has two wheels.

And it's green.

The Abstraction of a Class from an Object

Having examined an existing object a programmer can create a blueprint of that object. This blueprint, better known as a class, contains all of the elements that defines an idealized object. In this case it's a motorcycle class:

public class motorcycle
{
public String Manufacturer;
public String Model;
public double EngineSize;
public int no_gears;
public int current_gear;
public int maximum_speed;
public static final int wheels = 2;
}

This process of extracting the key information about a class is know as abstraction, and here the color of the motorcycle is not important, but the fact that it has a color is. However, the number of wheels is important and so that is defined as a constant.

Creating One Class from Another Class

One very useful aspect of classes is the ability of a programmer to create a new class from an existing one. For example, the programmer can create a new type of motorcycle using the motorcycle class as a base. This new child class will have all of the same attributes as the parent class:

public class suzuki_rf600r extends motorcycle
{
public suzuki_rf600r ()
{
this.EngineSize = 600;
this.Color = "Red";
}
}

The child class is said to have inherited the characteristics of the parent class.

Instantiating an Object

At the moment the class are idealized objects. They are, for example, the bike in the bike catalog. They are not the real bike sat on someone's driveway. The next stage, therefore, to create the real object and use it in an application:

import java.applet.*;
import java.awt.*;
public class run_bike extends Applet
{
suzuki_rf600r my_bike = new suzuki_rf600r ();
public void paint (Graphics g)
{
g.drawString ("" + my_bike.EngineSize, 40, 75);
}
}

And so at the end of this process:

  • a general class has been abstracted from a real world object
  • child classes can inherit the characteristics of parent classes
  • classes are instantiated into objects to be used in an application

The programmer (Java or otherwise) can the goon in this way until they have represented everything that they need in their cyber-universe.

BNC101

Mark Alexander Bain - Mark Alexander Bain is a writer, Mo Bro and consultant for all aspects of software development at dsquared. He has also written regularly ...

rss
Advertisement
Advertisement
Advertisement