Anda di halaman 1dari 9

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++
• Oop is Categorized In 4th Generation language and non-
structured
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.
Inline Function:
The functions that are defied inside the class interface are
called inline functions.

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

* Oop is Categorized In 4th Generation language and non-


structured.
Pointers
• Dynamic variables/objects.
• Memory allocation is decided during execution phase
Syntax : int *a;
Parts Of Pointer Variables
• Value part
• Address part
Note:
Dynamic Memory Allocation Keyword Used: - NEW
Dynamic Memory Deallocation Keyword Used: - DELETE

Inheritance : (General Concept)


It is an important property of oop language with the help of
which some or all properties/futures characteristics are transferred
from one or more classes towards (one or more classes) newly
designed classes.
Note : It provides software reusability
Types Of Inheritance
• Single Inheritance
• Multiple Inheritance
• Multi-level Inheritance
Single Inheritance
If only one class features (might be all or some) are
transferred/shifted towards a unit class only ; that will be
categorized as single inheritance

Class A

Single
Inheritance
Class B

Conditions:
o No. of base classes should be one every time
o As well as no derived classes=1
Multiple Inheritance
In this type of Inheritance some or all of the futures of two or
more than two classes are being transferred towards any no. of
newly designed classes.

Class A Class B Class A Class B


Class C

Class C Multiple Inheritance Class D Class E

Conditions
o No. of base classes =>2
o No. of derived classes = any no.
Multi-level Inheritance
It is such type of Inheritance in which all of the futures are
transferred from an already derived class towards newly designed
class

Class A

Class B

Class C Multi-Level Inheritance

Class D

Conditions
o At least one class should be available that is already derived
class and from that class we drive some classes
Modes Of Inheritance
• Public
• Private
• Protected
Modes Class interface Derived Outside the
(Inside the class
class)
Public

Private

Protected
General Syntax Of Inheritance:
Class derived_class_name: Mode Of Inheritance (space)
base_class_name
Example:
Class circle: public shape
Class bsse: protected bcs

Friend functions
If we want to utilize the private data items and private
member functions out side the class (i.e main of the program) we
get help of friend functions
Syntax : friend(keyword) retur_type name(arguments)
COMPOSITION:
It is an important future of oop languages, that provides the
affect of software reusability ; here we obtain the features of
base/already designed calss be declaring/passing the objects o it in
the new clas.
Objective/target: Software reusability
Software (program as whole (OR) some part of it)

POLYMORPHISM:
Poly two or more than two & Morphism form/shape
It is an Important feature/property/characteristic of oop
language with the help of which a single entity behaves differently
• Function(s)
• Function Overloading
• Function Overriding
Implementation of Polymorphism
It can be implemented with the help of function overriding
concept as well as virtual functions.
Overrided Functions
Conditions For Function Overriding:
• Two or more than two function with the same name
• Function should be resided in different classes
Note: In function overriding our focus is on the definition of the
function that we want to override (i.e the functionality should be
different)

Virtual functions:
If any function decelerator signature is attached with the
keyword of “Virtual” it will have the characteristics of Virtual
function.
Pure Virtual functions:
If any virtual function is assigned the zero value at the time of
its declaration it is called pure virtual function.
i.e. virtual void show()=o;
Abstract Class:
If any class (interface) contains at least one pure virtual
function that is know as abstract class
Properties:-
o User/programmer is not allowed to design/create he object of
that class;
Concrete Class
Any class derived/inherited form an abstract class is know as
concrete class.
Note. User can create objects within the concrete class

Anda mungkin juga menyukai