0% found this document useful (0 votes)
30 views

Encapsulation Construct & Naming Encapsulation

Uploaded by

mokshithareddyy0
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Encapsulation Construct & Naming Encapsulation

Uploaded by

mokshithareddyy0
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

ENCAPSULATION

CONSTRUCT & NAMING


ENCAPSULATION

PRESENTATION BY:
S.NAINJEETH KOUR
22321A1254
ENCAPSULATION :
Encapsulation is defined as binding together the data and the functions
that manipulate them.

Two important properties of encapsulation:


• Data Protection
• Information Hiding

Benefits:
• Data Protection
• Increased Security
• Code Reusability
• Improved Maintainability
ENCAPSULATION CONSTRUCTS

When the size of program reaches beyond reaches a few thousand lines,
we have 2 problems:

• Large Collection of subprograms make it hard to manage.


• Larger programs are hard to recompile.

This is where we use encapsulation for recompiling a part of program


without recompiling the whole.

Encapsulations are often placed in libraries and made available for reuse
in programs other than those for which they were written.
ENCAPSULATION IN C: 4

 It is done using header files.


 Collection of related functions and data definitions
can be placed in the file & compiled independently
such files are called header files.
 When such library is used the header file is included
in client code using #include preprocessor
5
ENCAPSULATION IN C++ :
It can be achieved in two ways:
• Header files
• Class

A class is a collection of variables and


functions.
In the code given , the integer
x(private) can only be accessed and
manipulated only using the functions
get() and set() which are present
inside the class. Thus we can say
that here, the variable x and the
functions get() and set() are bound
together which is nothing but
encapsulation.
NAMING ENCAPSULATION: 6

Naming encapsulation defines name scope that assists in


avoiding the naming conflicts.
Each library can create its own naming encapsulation to
prevent its name from conflicting with the names defined in
other libraries or client code.

 Namespace in C++
 Packages in Java
7

NAMESPACE IN C++ :
One can place each library in its
own namespace and qualify the
names in the program with the
name of the namespace when the
names are used outside the
namespace.

We can access a variable outside


the namespace using resolution
operator (::)
PACKAGES IN JAVA : 8

Packages can contain more than one type def.

• Before creating a package we need to define it:


package stkpkg;

• If we want to access a class of the package:


stkpkg.mystack

• If we want to access an object of class:


stkpkg.mystack.topsub

• If we want to use it in other program:


import stkpkg.*;
import stkpkg.mystk;
THANK YOU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy