Thursday, April 19, 2012

Object Oriented Design


In this post, I am going to scratch the surface of one of the most and modern design techniques in the Field of programming, specifically, Java Object Oriented Design. Object Oriented Design, is the way and methods to produce an Object-like entities or ‘classes’, from Java perspectives.

The first step in OOD is to identify all the objects you want to manipulate and how they relate to each other, Object Oriented Design is the modeling way, and the methodology of thinking about objects. In OOD, you have to focus on the objects, rather than the logic you need to implement them.

When you say that you have designed an Object, let us say, car, for example; that means you have built the blue print for this car, or the model of the car that you want to manufacture, then you start building your cars based on this model.

In Java programming language, objects are modeled or implemented as classes. Each class represents a blue print for a specific object.To give a better thinking of objects, look around you, you will find many objects; ( Humans, Cars, Houses, Animals, etc. ). And of course, each object has its own properties and methods to act or to function in a given way.

For example, cars have the following properties; model, color, speed, type, etc. and have methods or functions, which use the above properties to do a specific function or action. Some of cars’ methods are; accelerating, slow down, stop, etc.

To have the car stop, for example, you need to use the brake pedal to stop it. The braking is a method or function in each car, and the brake pedal is a property.

If we want to model this in java, we have the car as our object, which have some properties like speed, brake, etc. which have some methods like braking, accelerating, etc.

Note that the action of braking is a function; in java words, a method. The action of braking uses a property in the car which is brake pedal; if you trample on braking pedal, the car will do the action of braking.

Let us implement the above car object using java language.

Public class Car {
   boolean brake = false;

   public void brake() {
      brakePedal = true;
   }
}

In the above listing, note that we have implemented the object Car using the class keyword, and the property using brake variable with initial value to be false, finally, we have implemented the function of braking, which will be implemented to toggle the value of brake from false to true.

The above listing is simple and useless class implementation. But it aims to illustrate the concept of objects, properties, and methods.
Java specifications have some defined rules and keywords that tell how Java implements the Object Oriented Design concept.
Before you know how to program in java you need to understand the Object Oriented Programming.

To know more about this subject, you can check the official site of Java technology tutorials. 

This is another good link that give a quick reference for the syntax of Java language.