Page 132 - Computer science 868 Class 12
P. 132
4.4 BASIC PRINCIPLES OF OOP
Object oriented programming paradigm is a very powerful concept as it includes the four pillars, called the four basic
principles which make the foundation of this paradigm. They are explained as under.
4.4.1 Encapsulation
Encapsulation is a procedure of combining data and functions together into a single unit or entity. As the member
functions are the only way to access the data, so both data and functions are kept safe from outside interference and
misuse in this concept. Thus, it leads to the important OOP idea of data hiding. This helps data to be secured as it
cannot move freely from function to function.
A real-life example is a capsule. In general, a capsule is a small case or container,
especially round or cylindrical in shape which protects the drug inside it from getting Methods Variables
contaminated with the dust particles outside. Class
Similarly, Methods and Variables are enclosed within a unit called class. This wrapping Concept of Encapsulation
up of data members and member methods together into a single unit is called Encapsulation.
Let us see the application of encapsulation in Java programming.
class geometry
{
private int length, breadth, area, perimeter;
geometry(int l, int b)
{
length = l;
breadth = b;
}
void calculate()
{
area = length*breadth;
perimeter = 2 * (length + breadth);
}
void display()
{
System.out.println("Area " +area);
System.out.println("Perimeter "+perimeter);
}
}
In the above example, the data members (length, breadth, area and perimeter), constructor (geometry) and methods
(calculate and display) are all included within the class. So, we can say that they are encapsulated within a class
“geometry”.
4.4.2 Data Abstraction
The word abstract means existing in thought as an idea but does not have a tangible existence.
Suppose, a person is working in a bank. His key role is to enter the details of the customers’ transactions into the
computer (bank software). He is least bothered about how the data he enters is stored in the computer, or he doesn’t
have to do with how it updates the balance in the customers’ accounts. He just checks whether the data he enters is
correctly placed in the database or not. This act of entering data into the computer without thinking about the behind
procedure is known as Data Abstraction. This characteristic feature is very essential to keep the details safe.
130130 Touchpad Computer Science-XII

