Object Oriented programming

আমরা জীবজগতের শ্রেণীবিন্যাস জানি। যেমন : মানুষের বৈজ্ঞানিক নাম Homo sapiensMammalia বা স্তন্নপায়ী শ্রেণীর একটি প্রাণী মানুষ। এ শ্রেণীতে রয়েছে বানর ও শিমপান্জী সহ আরও অনেক। তাহলে,Mammalia class টির সকল বৈশিষ্ট্য মানুষ,বানর ও শিমপান্জীর রয়েছে। অর্থাৎ Mammalia Class এর Object হল মানুষ/বানর/শিমপান্জী কারন এরা প্রত্যেকে Mammalia Class টির Representative । এটাই OOP এর মৌলিক ধারনা।

C ও C++ এর মধ্যে পার্থক্য হল C++ এ OOP(Object Oriented programming) এর সুবিধা রয়েছে যা JAVA তে পূর্ণতা পেয়েছে ।
Object Oriented programming আমাদের যে সুফলগুলো দিয়েছে সেগুলো হলঃ
01. Data Encapsulation
02. Data Hiding
03. Polymorphism
এই তিনটি সম্পর্কে পরবর্তীতে বিস্তারিত বলব।

প্রোগ্রামিং করার সময় আমরা যখন কোন Class এর Declaration দিব তখন ঐ Class এর বস্তু বা Object এর কি কি বৈশিষ্ট্য থাকবে তা নির্ধারণ করে দেব। দুই ধরণের বৈশিষ্ট্য থাকতে পারে, ১। Attribute ২। Member function

উদাহরন:
[code]
Class Car{ // Car is the user defined classname
//these three are attribue of the class Car
Char carname[20];
int wheel;
char color;

//these are the member functions
void getnameofcar(){
cin>>carname;
}
void getnumberofwheel(){
cin>>wheel;
}
}; //a semicolon must be placed after the declarationof that class
[/code]
তাহলে দেখা যাচ্ছে যে Car শ্রেণীর সকল Object এর তিনটি Attribute থাকবে যথাঃ carname,wheel এবং color । এবং ২ টি function আছে। এই বৈশিষ্ট্যগুলো তিন ধরনের হতে পারে যথাঃ public, private and protected.

An example :
[code]
#include<stdio.h>
#include <iostream>
using namespace std;

Class Car{ // Car is the user defined classname
//these three are attribue of the class Car
Char carname[20];
int wheel;
char color;

//these are the member functions
void getnameofcar(){
cin>>carname;
}
void getnumberofwheel(){
cin>>wheel;
}
}; //a semicolon must be placed after the declarationof that class

int main(){

Car obj1,obj2; // declaring of an object of Class Car

obj1.getnameofcar(); // calling the function for obj1
obj1.getnumberofwheel();

obj2.getnameofcar(); // calling the function for obj2
obj2.getnumberofwheel();

cout<<ob1.carname<<endl;
cout<<ob1.wheel<<endl;

cout<<ob2.carname<<endl;
cout<<ob2.wheel<<endl;

return 0;
}[/code]
/////////////////////////////////////////

Definitions:
A class is a template for multiple objects with similar features. Classes embody all the
features of a particular set of objects.

An instance of a class is another word for an actual object. If classes are an abstract
representation of an object, an instance is its concrete representation.

Object is the more general term, but both instances and objects are the concrete representation of a class.
In fact, the terms instance and object are often used interchangeably in OOP language. An instance of a Car and a Car object are both the same thing.

One Reply to “Object Oriented programming”

Leave a Reply

Your email address will not be published. Required fields are marked *