Principles of OOP


Class

Class is the collection of data and functions means class encapsulates the data and function this is feature of object oriented programming.  Objects are the variable of class one can imagine class as structure in C.  You can created any number of object of class ( using the concept of array of objects it is very easy to create large number of objects).

 

Objects

Objects are basic run time entity in object oriented system. They represent a place, a bank account, or person.  Objects are the instance of class or a variable of user defined data types. When you declare a class there is no memory for data, after creation of class memory is allocated for data and this process is called as instantiation. Each object has its own copy of instance variable of its class. It means any changes to the variable of one object have no effect on another variable.

 

Object Oriented Programming

Data Abstraction

Data abstraction refers to the process of hiding complex and unnecessary information. Classes use the concept of data abstraction and are defined as a list of abstract attributes such as size, weight and cost. Real time example of data abstraction would be ATM machine user withdrawals cash without knowing it internal working, another example would be index of a book.

 

Data Encapsulation

Data encapsulation means encapsulating data and member function inside a single unit and this unit is nothing but a CLASS.  Data encapsulated inside this class is only accessible to the member function of class

Inheritance

Inheritance is striking feature of OOP. Inheritance means one class inherits the properties of another class. Using Inheritance re-usability can be achieved.

Polymorphism

Polymorphism is the ability to take more than one for.  Polymorphism means  function behaves according to the instance for example consider the operation of finding area if two arguments are passed to function it will return area of rectangle, if 3 arguments are passed it will return area of a cube.

Inline Function

Inline function is similar to macro. When normal function is called control is transferred to the function and this process takes lots of extra time in executing series of instructions to avoid this concept of inline function have been introduced. When inline function is called code associated with inline function is substituted. One biggest disadvantage of inline function is that wastage of memory.

Friend Function

As explained earlier that only member function can access private data of class but there could be situation when we need two classes to share a function. In such situation we can use a common function “FRIEND FUNCTION”. Friend function has access to both classes.

 

OOP Model

 

Syntax for friend function is as follows:

Class Student

{

Private:

int mark1,mark2

Public:

int roll

void getdata()

{

Mark1=50;

Mark2=60;

}

Friend void myfriend(void)

};

Constructor

Constructor is a function it job is to do automatic initialization of data upon creation of object. Constructor neither takes any argument nor returns any value. Class name and constructor name is always same.

Facebooktwittergoogle_plusredditlinkedinmailFacebooktwittergoogle_plusredditlinkedinmail

About Sourabh Bhunje

Sourabh Bhunje, B.E. IT from Pune University. Currently Working at Techliebe.

Professional Skills: Programming – Software & Mobile, Web & Graphic Design, Localization, Content Writing, Sub-Titling etc.

Leave a comment