Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

8. Explain encapsulation principle.

Posted on 2015-01-23
3
77 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

861 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