Solved

8. Explain encapsulation principle.

Posted on 2015-01-23
3
75 Views
Last Modified: 2015-01-25
Explain encapsulation principle.
Provide the best and comprehensive examples/analogues of encapsulation.
0
Comment
Question by:Nusrat Nuriyev
  • 2
3 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 40567779
I am having a hard time doing that better than Wikipedia explains it at http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29

In a nutshell, it is the way of only providing necessary information of peering components in a component related or object oriented environment with the background of creating some sort of abstraction in between these components/objects/classes. The basic idea behind that is to allow code changes that don't affect other people's code in the 1st place, since code they wrote on behalf of the classes/objects provided by the author isn't accessible by language design in the 1st place.
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40568110
Yeah, it's hard to explain. I've personally faced with this while trying to explain to my students.
Could you provide childlike explanation? :) Maybe, by providing some analogue from the life :)

>>> The basic idea behind that is to allow code changes that don't affect other people's code in the 1st place
on the 1-st place, you do mean by priority of importance of encapsulation language feature?

Could we say, that encapsulation is kind of language featured code protection mechanism, which defends code which should not be changed, unless you know what you are doing, it protects internal mechanisms of the entity which regular user (for example, another class, what else?) must not be aware of?
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40568157
>> Could you provide childlike explanation? :)

Hmm, OK, let's think of it like a cople of companies that work together and also compete with each other. So it is necessary for them to offer some access to each other (placing an order or inquiring about one) yet at the same time keep things like balances and resources a secret.

Or, maybe a group of co-workers - while they need to interact, they are trying to keep their salaries a private thing so noone feels envious ;o)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question