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

Explain how can you tell whether two strings are the same?

578


write a program to reverse a every alternetive words in a string in a place. EX: Input is "this is the line of text" Output should be "shit is eht line fo text" Please any one tell me code for that.

1569


how to print the character with maximum occurence and print that number of occurence too in a string given ?

2029


Difference between constant pointer and pointer to a constant.

605


Linked lists -- can you tell me how to check whether a linked list is circular?

633






how to make a scientific calculater ?

1552


develop algorithms to add polynomials (i) in one variable

1729


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

613


How can I read/write structures from/to data files?

544


Describe static function with its usage?

602


How can a program be made to print the name of a source file where an error occurs?

721


Can we declare a function inside a function in c?

574


What is bubble sort technique in c?

580


Can a function argument have default value?

657


Why we use void main in c?

584