-->

object oriented programming(OOP)

 Concept of POP (procedural oriented programming):- Conventional programming using high level languages such as COBOL,FORTRAN and C, is commonly known as procedure oriented programming(POP).

                                        Procedure oriented programming basically consists of writing a list of instructions(or actions) for the computer to follow, and organizing these instructions into groups known as functions. While we concentrate on the development , very little attention is given to the data that are being used by various functions.

            Diagrammatically we can show POP as 


Some characteristics (features) of Procedure Oriented Programming are :-

1) Emphasis is on doing things(algorithms).

2) Large programs are divided into smaller programs known as functions.

3) Most of the functions share global data.

4) Data more openly around the system from function to function.

5) Functions transform data from one form to another.

6) Employs top-down approach in program design.


OOP (Object Oriented Programming)concepts:-

The major motivating factor in the invention of object oriented is to remove some of the flaws encountered in the procedural oriented approach. Object oriented programming uses concept of “Object” and treats data as a critical element in the program development and does not allow it to flow freely around the system. It ties data more closely to the functions that operate on it, and protects it from accidental modifications from outside functions.

Some characteristics (features) of Object Oriented Programming are :-

1) Emphasis is on data rather than procedures or algorithms.

2) Programs are divided into what are known as objects.

3) Data structures are designed such that characterize the objects.

4) Functions that operate on the data are tied together in the data structure.

5) Data is hidden and cannot be accessed by external functions.

6) Objects may communicate with each other through functions.

7) New data and functions can be easily added whenever necessary.

8) Follows bottom-up approach in program design.

Terms:

  1. An instance of a class is known as an object.

  2. Every object has state and behaviour.

  3. The state is determined by the current values that are stored in the instance variables.


Understanding different terms (features) of OOP:

Object:-

An object can be considered a "thing" with some attributes and  can perform a set of related activities. The set of activities that the object performs defines the object's behavior. For example, the hand can grip something or a Student(object) can give the name or address. They all have state and behavior. like ,Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes).

   For example if “customer” and “account.” are two objects in a program, then the customer object may send a message to the account object requesting for the bank balance. Each object contains data and code to manipulate the data. Objects can interact without having to know details of each other’s data or code. 


Class:-

In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created. So it can be said as collection of same type of objects.for example in java,

public class HelloWorld 

{

        public static void main (String[] args) 

    {
System.out.println ("Hello World!");
    }
}

Or

simply we can create by writing ,

class name

{

members;

functions;

}

here, we can see a class named helloworld.It displays output hello world! by creating a class we create an object/s.

Or 

If fruit has been defined as a class, then the statement fruit mango; will create an object mango belonging to the class fruit.


Inheritance 

Inheritance is mainly used for code reusability.In the real world there are many objects that can be specialized. In OOP, a parent class can inherit its behavior and state to children classes. Inheritance means using the Predefined Code. This is very main feature of OOP, with the advantage of Inheritance we can use any code that is previously created. This concept was developed to manage generalization and specialization in OOP.  Lets say we have a class called Car and Racing Car . Then the attributes like engine no. , color of the Class car can be inherited by the class Racing Car . The class Car will be Parent class , and the class Racing Car will be the derived class or child class

The following OO terms are commonly used names given to parent and child classes in OOP:

Superclass: Parent class.

Subclass: Child class.

Base class: Parent class.

Derived class: Child class

It can have many types.

single inheritance:-one derived class inherits property from one base class

multiple              “  :- one derived class inherits property from many base classes.

multi level          “ :-in this many derived classes are inherited from many base classes

hierarchical       “ :-under this many derived classes can be inherited from single base class

hybrid                 “:-it’s a combination of hierarchical and multilevel.

Abstraction 

Abstraction is simplifying complex reality by modeling classes appropriate to the problem . In other words it means representing only the important details without including all the details . For example the car Ferrari can be treated as simple car only .

Or

It is a Process of exploring relevant details and hiding irrelevant details this feature is known as Abstraction. In other way making simplicity to use complex system. One does not want to understand how to engine works. Similarly one does not have to understand the internal implementation of the software objects.

Abstraction Example : Engine, Driving.

                                  Abstraction main advantage is that every user will get data according to their exact requirement. User will not get confused with unnecessary data. The following example program will make you to understand Abstraction.

               Abstraction is way of converting real world objects in terms of class. For example creating a class Vehicle and injecting properties into it. E.g

public class Vehicle {

public String colour;

public String model;

}


Encapsulation

           The wrapping up of data and functions into a single unit is called as encapsulation . Encapsulation means putting together all the variables (Objects) and the methods into a single unit called Class.The class acts like a container encapsulating the properties. It can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface.For example the class car has a method turn ()  .The code for the turn() defines how the turn will occur . So we don’t need  to define how Mercedes will turn and how the Ferrari will turn separately . turn() can be encapsulated with both.


Polymorphism

Its an important OOPs concept , Polymorphism means taking more than one forms .Polymorphism gives us the ultimate flexibility in extensibility. The ability to define more than one function with the same name is called Polymorphism.Polymorphism allows the programmer to treat derived class members just like their parent class’s members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to calls of methods of the same name .If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). Each subclass overrides the speak() method inherited from the parent class Animal.

Or 

Example, in chemistry, carbon exhibits polymorphism because it can be found in more than one form: graphite and diamond. Each of the form has it own distinct properties.

Or

Simple example of Polymorphism, look at an Account (it may be checking or saving assuming each attract different dividends) you walk in a bank and ask a teller what is my balance? or dividends? you don't need to specify what kind of an account you're having he will internally figure out looking at his books and provide you the details. Internal details on how the teller  works are hidden from you for each case (checking and savings) where as anybody can walk in and ask the question and get the answer suitable to the person in question. So the teller is polymorphic (he's changing his working rules or forms) to suit the customer.


besides these all we have many others part s of OOP like,dynamic binding,message communication

Advantages of OOP:-

1. Simplicity: 

Software objects model real world objects, so the complexity is reduced and the program structure is very clear. 

2. Modularity: 

Each object forms a separate entity whose internal workings are decoupled from other parts of the system. 

3. Modifiability: 

It is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods.

4. Extensibility: 

Adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones.

5. Maintainability: 

Objects can be maintained separately, making locating and fixing problems easier.

6. Re-usability: 

Objects can be reused in different programs.

   we can apply these all by using its features object,class,polymorphism,data abstraction, encapsulation  etc. 

Application of OOPs:

Main application areas of OOP are:

  1. User interface design such as windows, menu ,…

  2. Real Time Systems

  3. Simulation and Modeling

  4. Object oriented databases

  5. AI and Expert System

  6. Neural Networks and parallel programming

  7. Decision support and office automation system

  8. in CAE/CAM/CAD system

  9. system software.

          etc


No comments:

Post a Comment