|
||||||
A Brief Introduction to Object-Oriented DesignHow Use Abstraction, Inheritance and Instantiation in Java ClassesObject-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 ObjectsAn object is simply something that exists in the universe. Take, for instance, the Kawasaki Ninja ZX-10R. The Kawasaki Ninja ZX-10R:
And it's green. The Abstraction of a Class from an ObjectHaving 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 ClassOne 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 ObjectAt 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:
The programmer (Java or otherwise) can the goon in this way until they have represented everything that they need in their cyber-universe. BNC101
The copyright of the article A Brief Introduction to Object-Oriented Design in Computer Programming Tutorials is owned by Mark Alexander Bain. Permission to republish A Brief Introduction to Object-Oriented Design in print or online must be granted by the author in writing.
|
||||||
|
|
||||||
|
|
||||||