0% found this document useful (0 votes)
9 views26 pages

Abstraction

Uploaded by

tc9466
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views26 pages

Abstraction

Uploaded by

tc9466
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Abstraction

● It is necessary to separate the necessary


details from unnecessary details
● It simplify programming process
● It focus on essential attributes and ignore
subordinates attributes.

Introduction
Advantages:
● One can use an object without knowing
its details.
● We can distinguish between what a
program does and what it can be
implemented.

Introduction
Abstraction is of two types:
● Process Abstraction
● Data abstraction

Introduction
Process Abstraction
● Process abstraction is an action of computation
in a set of input objects and output objects
produced.
● Subprogram has its name,declaration,procedure
and functions
● A subprogram act as Black box. The details are
hidden from outside world.
● Program has 3 sections:Input,Process,Output

Advantage: It is easy to construct,read and


understand large program
Introduction
Data abstraction
●Program is divided into objects.
●Inner details of the objects are hidden
from the outside world
●Objects can be accessed by private
members but not be accessed by public
members.
●There is no need to look its inner details.
●Classes use this concept.

Introduction
Information hiding

● Private information are not available


outside the object and can’t be altered by
external environment.
●Access to private part of an object is
restricted that the function of object can
can only access the data.

Introduction
Information hiding

Advantages
● Easy to understand
● Portable
● Secure
● Only essential info is visible
● Changes is restricted to small subset of
total program

Introduction
Encapsulation

● Wrapping up of data and information into


a single unit is called encapsulation
●Used data structure is hidden but it
provide well defined interface.
●Data & set of info can’t be viewed and
manipulated by user.
Need:
●It organize program into a group of
modules.
Introduction
Encapsulation

Advantages:
●Easy modification
●Access control to entities
●Organize a program in such away that it
limits recompilation

Introduction
Abstract data type

∙ It is a specification of set of data and set


of operations that can be performed on
that data.
∙ It is independent of various
implementation.
∙ It has 2 parts:Data and operation
∙ Two operations can be performed on
ADT
(1) Constructor
Introduction
Constructor:

●It is a member function of class that is


executed when we create new object of
that class.
●It has same name as the class.
●It doesn’t have any return type, not even
void.
●A default constructor doesn’t have any
parameter.
Introduction
Destructor:

●It is a member function of class that is


executed when an object goes out of
scope or whenever deleted.

●It has same name as the class but has


prefix(~).

●A can not take any parameter.


Introduction
Abstract data type

Properties:
●It export a type.
●It has a set of operations.
●Precondition define the application domain
of type.

Introduction
Abstract Data Type and Object Orientation

●ADT are referred as classes.

●It allow the creation of objects with well defined


properties and behaviour.

●Object oriented programming is :Programming with


ADT”.

●Program is divided into objects. Each object has its


own char.

●Object has Data members and member functions.

●Class members can be public and private.

●Inner details of objects are hidden which makes them


abstract. Overview of Management
Advantages of Abstract Data Type

● Increase the reliability.

●It organize program into logical units that can be


compiled separately.

●Modification can be done in a single area of program.

●Recompilation can be avoided.

●It take advantages of Encapsulation.

●Clients can’t see represent detail so it can be changed


at any time without knowledge of clients.

Overview of Management
Subprograms

●It is a building block of program.

●It is a set of statements that can be reused at different


places in a program when needed.

●It saves memory space and coding time.

●It increases the readability of program.

Characteristics:

● It has single entry point.

●The caller is suspended during execution of called


program.
Overview of Management
Subprogram example:
Int cube(int); prototype
Int main(){
Int y=5; actual parameters
Cout<<cube(y); Subprogram call
Int x=3;
Int cube (int x); subprogram
header
{
formal parameter
return x*x;
}
} Overview of Management
●Control is always return to caller when the called
subprogram’s execution terminates.

Advantages:

●Re usability
●Extensibility
●Modularity
●Maintainability
●Abstraction

Overview of Management
Procedure and Function

There are two types of subprograms:


(1) Procedure
(2) Function

●Procedure is defined as subprogram that define


parameterized computation. It has two parts:

● Specification:It begin with keyword PROCEDURE and


end with procedure name or parameter list.

●Body begin with keyword BEGIN and end with keyword


END. It has three parts:
●Declarative part
●Executable part
●Optional exception handling part
Overview of Management
Examples of procedures
Program example1; Program example2 ;

Specification Var
procedure add; x : integer ;
y : integer ;
var
x : integer ; Procedure add ( a : integer
y : integer ; ; b : integer );
begin begin
BODY write ( a + b );
read ( x , end;
y );
write ( x + y BEGIN
); x = 10 ;
end; y=5;
add ( 10 , 5 ) ;
Overview of Management
Function

●It is a subprogram that compute a value.

●It is a semantically modeled on mathematical


function.

●It has a return clause.

●It has no side effects. It doesn’t modify


parameters and variables defined outside the
function.
Overview of Management
Function Procedure
1.deals with an expression 1. does not deal with an
2. used to calculate something expression
from a given input 2. is a set of command which
3. can be called by procedure. are executed in a order
4. can be called through sql 3. can not be called by
queries function
5. each time function are 4. can not
compiled when they are called 5. Procedure are compiled
once and can be called
again and again

Overview of Management
Overloaded subprograms

It is a subprogram that has same name as another


subprogram in the same referencing environment.

●It must have a unique protocol.

●It must be different from others in number, order ,types of


its parameters, or its return type if it is a function.

●It perform different activities depending on kind of data


sent to it.
●The meaning of call is determined by actual parameter list.
●It provide a particular type of polymorphism called ad-hoc
polymorphism.

●For example:add(); add(int,int);


Overview of Management
Overloaded subprogram

Advantages:

●Reducing the subprogram names to be remembered.

●Useful for handling different types of objects.

Overview of Management
Generic Subprogram
A generic or polymorphic subprogram is one that takes parameters
of different types on different activations.

●Overloaded subprograms provide ad hoc polymorphism.

●A programmer should not need to write 4 different sort programs


to sort 4 arrays that differ only in element type.

●A subprogram that takes a generic parameter that is used in a


type expression that describes the type of the parameters of the
subprogram provides parametric polymorphism .

Overview of Management

You might also like