3.Procedural Programming vs Object Oriented Programming

Friday, August 7, 2009 Posted by Sudarsan
Procedural Programming

The Procedural programming Involves dividing a large program into a set of subprograms or small module that perform specific tasks. And also can be defined as a Module consists of single or multiple procedures or sub programs.

These Procedures are also known as functions, routines, subroutines, or methods in various programming languages. In a program following procedural methodology, each step of a subprogram is linked to the previous step. This type of programming is aimed at for developing simple applications.

Although procedural programming methodology has various benefits over the simple sequential programming:

• In Procedural Programming Easy to read program code.

• Easy maintainable program code as various procedures can be debugged in isolation.”

• Source Code is more flexible as you can change a specific procedure that gets implemented across the program.

• Most of the data is shared as global that can be accessed from anywhere within the program (Even in Sub Procedures and Simple Modules).

Need for Object Oriented Programming

A large application or software consists of component objects, which interact and communicate with each other. This can be used to develop various high-end, scalable applications.

Advantages of Object Oriented Programming

1. The object-oriented model gives the real world more accurately than the traditional, procedural approach. This is called Real-World Programming.

2. In the object-oriented methodology, we can build classes; these classes can be used by several applications to enable Reusability of Code

3. Object-oriented programming also enables us to evolve various versions of software. When a change is suggested, the old system need not be completely abandoned and re-built from scratch. This offers to Resilience to change.

4. Information hiding or Data Hiding enables us data security in an application.

5. Concept of Object Oriented Paradigm is used to create graphical and numerical building blocks that can be assembled to form portable, flexible, and cost effective solutions for various real life problems.

6. All the adventure games, sports games, and the space games are modeling some type of objects present in the real world.

7. We can organize a game into a collection of "things,” when you apply OOP techniques to the design.

More about Object Oriented Programming

The main concept behind Object Oriented Programming is all about Classes and Objects. These are basic building blocks of OOP.An object will have state, behavior and identity.

A program is said to be object oriented it must satisfy the fallowing properties.

1. Encapsulation

2. Abstraction

3. Inheritance

Encapsulation

Grady Booch, defined the encapsulation feature as fallows

“Encapsulation is the process of hiding all of the details of an object that do not contribute to its essential characteristics.”

Encapsulation is the feature that provides security to the data as well as the methods of a class.



Abstraction: Grady Booch defined the encapsulation feature as:

“An Abstraction denotes the essential characteristics of an object that distinguishes it from all other kinds of objects and thus provides crisply defined conceptual boundaries, relative to the perspective of the viewer.”

Abstraction refers to the attributes of an object that clearly demarcates it from other objects.

The concept of abstraction is implemented in object-oriented programming by creating classes.

Note: Encapsulation hides the irrelevant details of an object and abstraction makes only the relevant details of an object visible.

Inheritance:

This enables us to extend the functionality of an existing class and also enables you to add new features and functionality to an existing class without modifying the existing class so that we can share data and methods among multiple classes.

Super Class and Sub Class

A superclass or parent or base class is the one from which another class inherits attributes and behavior.

A subclass or child or derived class is a class that inherits attributes and behavior from a superclass.

The relationship among the classes can be classified as:

• Kind-of

• Is-a

• Part-of

• Has-a

Java and Inheritance

Java supports Single and Multiple inheritance.

Single Inheritance: This can be defined as “A subclass can be derived from only one superclass”.



For instance, see the fallowing diagram



Multiple Inheritance: This can be defined as “a sub class is derived from more than one superclass”.



An example of multiple inheritance is shown below



Another example is also given below



Polymorphism: This is derived from two Latin words-Poly, which means many, and morph, which means forms.

Assigns a different meaning or usage to an entity in different contexts.

Post a Comment