Posted by: ahmedashfaque | December 13, 2014

Beauty of object oriented design part 1


Software programming & design has evolved from procedural programming & design to object oriented programming & design. People try to understand what is the difference and how object oriented programming & design can be used to create software products.

Not many people understand the beauty and power of object oriented design. Let us understand these aspects here.

In object oriented design, we have objects, super classes, child classes and underlying data structures and methods to work on these data structures. People often fail to understand how to implement object oriented design in its full glory and beauty.

Suppose you have to create a software product for a construction company. The company builds buildings and sells residential units to its customers. Some of the important entities here will be customers, the construction company, buildings, residential units inside these buildings etc. let us think about the buildings and residential units in these buildings. How you will represent these buildings and residential units in the software product? Some of the states of the buildings include built up area, plot size, number of residential units, number of storeys in each building etc. Some of the behavior of these buildings could be under construction,

Since we assume there will be many such buildings, we can think of a super class of all buildings first. Since we are also thinking of making many child classes from this super class, we can create an interface for this super class. It is because, buildings are being created to cater to different categories of people. So we have costly luxury buildings, then we have semi luxury buildings and then we have economy class buildings. So we will have 3 child classes for these 3 types of buildings. Each individual building will be the real object.

You can see that now we have modeled our buildings correctly. Let us see our design:

Super class – Building. It will have an interface with state definition for plot area, number of residential units, number of storeys etc.

Child classes – luxury_buildings, semiluxury_buildings, economy_buildings. Each of these classes will implement the interface through the “Implements” statement. Each child class also need to be extended from the super class through “Extends” statement.

Objects – each particular building in each building type. For example we will have building number 1, building number 2 for luxury buildings; building number 1, building number 2 for economy buildings etc.

Our code will look like this:

The super class definition:

public interface buildings {
void built_area(newValue);

}

The child class definition and objects inside:

public class luxury_buildings implements buildings {

int built_area = 100;

void built_area(newValue){

built_area = newValue;
}

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: