Download as pps, pdf, or txt
Download as pps, pdf, or txt
You are on page 1of 17

Course : MCA

Semester : II
Subject Code : MC 0066A
Subject Name : OOPS Using C++
Unit Number :1
Unit Title : Introduction to OOP & C++
Lecture Number :2
Lecture Title : Introduction to OOP & its
basic features

1
HOME NEXT
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Introduction to OOP & its basic features

• Introduction to OOP

• Basic Features of OOP

C o n f i d e n t iNEXT
PREVIOUS al
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Objects

• Program representation of some real world thing (i.e person, place


or an event)

• Have both attributes (data) and behaviors (functions or methods)

Polygon Object Bank Account

Attributes Behaviour Attributes Behaviour


Position Move Account number Deduct Funds
Fill Color Erase Balance Transferfunds
Bordercolor Changecolor DepositFunds
Showbalance

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Classes

• Objects with same data structure and behavior are grouped

together as class.

• Objects are “instances” of a class.

• Example: Class-Car, Object-Maruthi

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Encapsulation

• Data and functions are capsulated into a single unit.

• Provides security to data by hiding the data.

• Example:Class Car encapsulates its attributes like color,

manufacturer, model and its properties like go, stop, turn left etc.

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Inheritance

• Allows to derive a class from an existing class and inherit all the

characteristics and behavior of the parent class.

• Allows easy modification of existing code and also code reuse.

• Example:Class Light Motor Vehicle inherits from the class Vehicle

and the class Car in turn inherits from the class Light Motor

Vehicle

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Polymorphism

• Poly means Many.

• One function can perform many actions.

• Example: The operator + can be used to add two numbers or to

concatenate two strings depending on the case

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Additional Resources

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Features of OOP

• Encapsulation

• Data Abstraction

• Inheritance

• Polymorphism

• Message Passing

• Extensibility

• Persistence

• Delegation

• Genericity

• Multiple Inheritance

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Features of OOP

Encapsulation
Supported by
comprises
Data abstraction

Single inheritance
Object C++
Oriented Polymorphism
Programming X
Paradigm
Persistence

Delegation

Genericity

Multiple inheritance
10

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Data Abstraction

• The technique of creating new data types that are well suited to
an application to be programmed is known as data abstraction.

• It provides the ability to create user-defined data types, for


modeling a real world object, having the properties of built-in data
types and a set of permitted operators.

• The class is a construct in C++ for creating user defined data


types called Abstract Data Types (ADTs).

11

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Multiple Inheritance

• The mechanism by which a class is derived from more than one


base class is known as multiple inheritance.

• Instances of classes with multiple inheritance have instance


variables for each of the inherited base classes.

• C++ supports multiple inheritance

12

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Message Passing

• It is the process of invoking an operation on an object.

• In response to a message, the corresponding method (function)


is executed in the object.

• C++ supports message passing

13

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Extensibility

• It is a feature, which allows the extension of the functionality of

the existing software components.

• In C++, this is achieved through abstract classes and inheritance.

14

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Persistence

• The phenomenon where the object (data) outlives the program

execution time and exists between execution of a program is known

as persistence.

• All database systems support persistence.

• In C++, this is not supported.

• However, the user can build it explicitly using file streams in a

program.

15

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Delegation

• It is an alternative to class inheritance.

• Delegation is a way of making object composition as powerful as


inheritance.

• In delegation, two objects are involved in handling a request: a


receiving object delegates operations to its delegate.

• This is analogous to the child classes sending requests to the parent


classes.

• In C++, delegation is realized by using object composition.

• Here, new functionality is obtained by assembling or composing


objects.

• This approach takes a view that an object can be a collection of


many objects and the relationship is called the has-a relationship or
containership.
16

PREVIOUS i d e n t i a NEXT
C o n f HOME l
Unit-1 Introduction to Object Oriented Programming (OOP) & C++

Genericity

• It is a technique for defining software components that have more

than one interpretation depending on the data type of parameters.

• Thus, it allows the declaration of data items without specifying

their exact data type.

• Such unknown data types (generic data type) are resolved at the

time of their usage (function call) based on the data type of

parameters.

• In C++, genericity is realized through function templates and class

templates.

17

C o n f i d e nHOME
PREVIOUS tial

You might also like