Sei sulla pagina 1di 6

OBJECT ORIENTED PARADIGM

OOP
• It is a high level programming language
• It is based on objects and deals with object manipulation. e,g
Java ,C++
Object
It is an instant of class that defines the real entity in detail.
OR
It is a layout(pattern) that reflects (defines) the original entity in detail.
Note:- An object have the same relationship with the class as that of variable may
have with primitive data type.
Entity
It is the name property of a Object/Event/Person. There are two type of entity.
• Physical
• Logical
Physical Entity
These entities are tangible in nature. e,g. (a)Person (b)Place (c)object
Logical Entity
These entities are intangible in nature. e,g. Event
Object Manipulation
If various operations/functions/methods are applied on objects, that is named
as object manipulation.
C++ Data Types
 Basic/ Default / Primitive data types (Used in structural
programming )
 User Defined data types (Used in OOP)
Basic/ Default / Primitive Data Types
These are the data types that are available by default to every
user and he/she can use it by following standard rules
User Defined Data Types
These are the data types that deal with the real time objects.
Example : Classes , Structures
Primitive Data Varibles Class Object
Types
Int, float x, y User Defined L1
Char etc.. a,b,c Data Type Vc
etc.. e,g : Library S1 etc..
gcuf etc..

CLASS
It is a template (Layout, blue print) that generates numberless real time
objects.
Class interface/class specification+ class interface/class definition
Technical Definition
Class=Variable (Objects) +Object manipulation
OR
Class=Variable (Objects) +procedures/methods/functions
Data Items Or Data Members
Components or constituents of class
OR
These are the data members (Variables) of the class, that
defines the properties/characteristics of the class declared.
These are considered as private however not necessary condition.
Note : By default the status of data items is private in the class.

Member Functions
These are the methods/procedures/operations that are applied
on the data (i,e data items) for obtaining the desired
results/objectives.
Note : In general the status of data items is public in the class
however not necessary condition.
Note : If we never write any thing inside the class every thing will
be private.

General Structure Of A Class


Class calss_name
{
private: Access Specifier
Data_item(1);

Data_item(n);

public:
member_function(1);

member_function(n);
};

Access Specifier
These are the keywords/reserved words ,acts as indicator for
the compiler (included by the programmer inside the class interface)
according to which the properties of data items as well as member
function are defined.
(OR)
These are the Keywords that provide the accessibility for the
user/programmer being included inside the class interface.

Syntax
public:--------(1)
private:-------(2)
protected:----(3)
Access Class interface Implementation Main (Main of
Specifier (Inside the (Outside the the program
class) class)
Public

Private

Protected

Public
It is such a specifier,if it is included in a class interface every
element written afterwards should contain following features:
//for input from the user
void get_data(int x,float a, char s)
{
roll_no=x;
age=a;
sex=s;
}
Features of class
• User defines data type.
• Declaration: The Keyword of ‘class’ is used for
declaration.
• Members : It might contain of data items or member
functions or both
• Default Status: By default data items are private:
Use Of Class
It is used in Real time for solving any real world problem

Scope Resolution Operator


It is such an operator that associates/combines member
function definition with there relevant decelerators.
Note : This operator is use for definition out side the class.
Syntax
Class_name::member_function_name (arguments)
Constructor:-
These are the special member function that are used to
initialize the data items
int x;
flaot y;
usage
Initialization of data items.
Properties/principle/features/constituents
o Constructor should have same name as that of class name
e,g class Macdonald
Macdonald ( )
o Constructor have no return type not even “void”.
o These functions cannot be called explicitly by the
programmer
o These functions get called automatically when ever any no.
of objects are called
o It might take any no. of arguments
o Constructor can be overloaded
Types Of Constructor
 Default Constructor
 Copy Constructor/Default Copy Constructor
Default Constructor
It is such a special member function that is designed by the
programmer explicitly or by the complier implicitly
o It exists as unity (only one)
o It takes no arguments
o Its purpose is to initialize the data item values with the
primitive data type to avoid garbage value.
e.g- class student
{
student ()
{
}
};
Default Copy Constructor
It is such a special member function that will assign the whole
values assigned to an already created object towards a newly
created object.
Syntax
1— student s1 (10,”azhar”,15);
student s2;
s2=s1;
2-- student s2(s1);
object passed as an argument
Function Overloading
It is a procedure/technique with the help of which functions
are overloaded
Conditions For Overloading
• If no. of arguments are changed
e.g.- void sum(int)
void sum(int. int)
void sum(int.int.int)
• If the order of arguments are changed
e.g.- void sum(int,float,char)
void sum(flaot,int,char)
void sum(char.flaot.int)
• If the data type of arguments is changed
e.g.- void sum(int,int)
void sum(long. long)
void sum(float.foat)

Destructor:-
These are the special member functions that are used to de
allocate already memory allocated to various objects

Properties/principle/features/constituents
o Destructors should have same name as that of class name
similar to the constructor
o Destructors have no return type not even “void”.
o These cannot be overloaded
o It should be declared public necessarily
o These functions cannot be called explicitly by the
programmer
o It will be called automaticall.
o
Memory Concept In Classes
There are mainly two types of memory in class
• Static memory
• Dynamic memory

Static memory(static binding, compile binding, early
binding)
If the memory allocation is finalize at the compile time of a
program ,it is called static binding.

Dynamic memory (Runtime binding, execution binging)


If the memory allocation is finalize at the execution time of a
program ,it is called dynamic binding.

Difference b/w Structures & Classes


Factors Structures Classes
Data type User defined User defined
Declaration Struct structure_name Class
Procedure Struct structure_name Class class_name
{ {
}; };
Members It consists of data item, It might contain data
variable, item or member
functions or both
Default Public: Private:
Usage Small scale applications Real time
applications for any
problem

Prepared By: Muhammad Azhar (907)

http://www.azhar.net.ms

Email- stylishguy1987@gmail.com

Potrebbero piacerti anche