C++ is one of the most versatile languages in the world. It is used nearly everywhere for everything… systems programming (operating systems, device drivers, database engines, embedded, Internet of Things, etc.)

Enter Header Image Headline Here

Thursday, 13 April 2017

C++ Procedural to OOP : Migration

                 C++ Procedural to OOP : Migration


The main purpose of c++ programming is to add object orientation to the c progranning language and classes are central feature of C++ that supports object- oriented programming.

C++ is a multi-paradigm programming language.Meaning, it supports different programming styles.

One of the popular ways to solve a programming problem is by creating object, known as object-oriented style of programming.

C++ supports object-orianted (OO) style of programming which allows you to divide complex problems in to smaller sets by creating objects.

Class :  

  • It is user defined data type combining data members and member functions.
  • A class is a blue prient for the object.
  • We can restrict the access of the member using access specifiers( public, private, protected)
  • By default every member in class is private.

How to define a class in C++?  :


  • A class is define in C++ using keyword class followed by the name of class.
  • The body of class ic defined inside the curly brackets and terminated by a semicolon ant the end.



Example : Class in C++ :
























Keywords : private and public


You may have noticed two keywords: private and public in the above example.


The private keyword makes data and function private. Private data and function can accessed only from inside the same class.

The public keyword makes data and functions public. public data and function can be accessed out of the class.

If you try to access private data from outside of the class, compilerr throws error. This feature in OOP is known as data hiding.



C++ Objects  :

  • It is the variable of class.
  • When class is define ,only the specification for the object is defined; no memory or storage is allocated.
  • Object gets physical memory and contains data members which are decleard in to the class. 



Characteristics of an object :

1. State : 

  • State of an object is determined by the values of data member of that object.
  • If two objects have same value of data members, then the two objects are having same state.


2. Behavior :

  • A member function in the class decides behavior of the object.
  • Two objects having different states will show different behavior by calling the same member function.

3. Identity : 

  • Every object has unique address.

Data Members : 


  • Data members are declared with any of the fundamental types, also with pointers, reference, array types and user- defined types.
  • By default every data member in class is private.
  • Initializer are not allows inside the class definition.


 Member Function:

1. Constructor: 


  •  It is a member function of the class having same name as that of class.
  •  It doesn't any return type. ( Not even 'void')
  •  Constructor is automatically called only once in a lifetime of an object when it is created.
  •  Constructor initializes data members of the class.
  •  If we don't write any constructor, compiler provides default constructor for the class.
  •  Constructor can be overloaded.





2. Destructor: 


  • It is a member function of the class having same name as that of class preceded by "~" .
  • It doesn't have any return type.  ( Not even 'void')
  • Destructor is automatically called when object goes out of scope.
  • Destructor de-initializes data members of the class.
  • If we don't write any destructor, compiler provides default destructor for the class.
  • Destructorr can NOT be overloaded.


3. Mutators :


  • Mutators are the member functions the class, hwich modify state of the object.
  • These functions modify values of the data members.
  • These are typically setterr functions in the class.





4. Accessers : 


  • Inspectors are the member function of the class, which read the state of the object.
  • These are typically getter functions in the class.


5. Facilitators:


  • Facilitators are the members of the class. which do not directly contribute to the operation of that class.
  • This function prvides additional functionally like scanning or printing objectm data,











0 comments:

Post a Comment

Popular Posts

Recent Posts

Categories

Unordered List

Text Widget