My audio blog is for this Page is here
OBJECT ORIENTED PROGRAMMING LANGUAGE :
Before getting to any formal definition , OOPS is just like any other programming language which aims to give programmer a better way to solve the problems and serve the user. It comes up with a way to express real world problems giving a much better perspective of the problem.
Object Oriented Programming Language considers the use of classes and objects. The classes help in binding the attributes ( variables) and methods(functions) into a single entity. It makes the entire code more manageable and gives better understanding.
WHY OBJECT PROGRAMMING LANGUAGE :
Though Procedural Programming can be made to do everything which the object oriented programming will do, OOP provides better readability and re usability. Reusability means that if you define a method in a class they can be used by all the object instances of the class and the classes derived from this Class. Readability comes from the binding of variables and function into the same class. It makes it easy to change the behavior of the object as they are coupled inside the class.
CLASSES :
Classes are the basic template from which the objects are made out. For example : Building can be a class with attributes like no.of.floors, type of building, etc. It declares the attributes which the classes should hold and the methods which it should do.
OBJECTS :
Objects are instances of class, in the sense that the class is a blue print and the objects are the real entity built from it.
For example : Class ball{
string color;
int size;
ball(string c,int s)
{
color=c,size=s;
}
}
int main()
{
ball b("blue",30);// object of ball having blue
// color and size of 30
}
Here the class ball contains the attributes of the ball. We can create any number of ball objects from the class and specifying the attributes of each object.
ABSTRACTION :
Abstraction is basically letting the user use what he really needs. It is also a good programming style to prevent unwanted access of variables or methods from different parts of the code which may lead to messy and error-prone code.
Eg :
Class TV{
private :
Data_type configuration;
public :
Change_config(Date_type new_config){...}
switch_on() {...}
switch_off() {...}
change_channel(int i){...}
}
int main()
{
TV Samsung_LED=new TV();
Samsung_LED.switch_on();
Samsung_LED.change_channel(10);
Samsung_LED.switch_off();
}
For a TV class the user only needs to call methods to do the basic operations without having any idea of how they work inside.
From a Programmer's point of view it is preventing unwanted accessing the methods or variables. If the Programmer wants to change the property of the TV ,
For example : if he needs to edit configuration of the TV ,he needs to change it within the TV class and not in any other part of the code. This helps in making a programmer avoid search through the entire code in case the configuration has a problem.
No comments:
Post a Comment