What is encapsulation?

Answer Posted / abalonesoft

Preventing unauthorized access to some piece of information
or functionality.

The key money-saving insight is to separate the volatile
part of some chunk of software from the stable part.
Encapsulation puts a firewall around the chunk, which
prevents other chunks from accessing the volatile parts;
other chunks can only access the stable parts. This prevents
the other chunks from breaking if (when!) the volatile parts
are changed. In context of OO software, a "chunk" is
normally a class or a tight group of classes.

The "volatile parts" are the implementation details. If the
chunk is a single class, the volatile part is normally
encapsulated using the private and/or protected keywords. If
the chunk is a tight group of classes, encapsulation can be
used to deny access to entire classes in that group.
Inheritance can also be used as a form of encapsulation.

The "stable parts" are the interfaces. A good interface
provides a simplified view in the vocabulary of a user, and
is designed from the outside-in (here a "user" means another
developer, not the end-user who buys the completed
application). If the chunk is a single class, the interface
is simply the class's public member functions and friend
functions. If the chunk is a tight group of classes, the
interface can include several of the classes in the chunk.

Designing a clean interface and separating that interface
from its implementation merely allows users to use the
interface. But encapsulating (putting "in a capsule") the
implementation forces users to use the interface.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In a header file whether functions are declared or defined?

742


What are the types of type qualifiers in c?

741


What is a memory leak? How to avoid it?

705


Why do we write return 0 in c?

649


Explain how do you sort filenames in a directory?

710






Is using exit() the same as using return?

779


write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.

2536


The statement, int(*x[]) () what does in indicate?

767


#include { printf("Hello"); } how compile time affects when we add additional header file .

1519


Is malloc memset faster than calloc?

713


how can i write a program that prints out a box such that whenever i press any key8(coordinate number) on the keyboard, the box moves.

1310


write a program to print data of 5 five students with structures?

1703


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

717


Explain the difference between the local variable and global variable in c?

703


Can we assign integer value to char in c?

718