Solved

8. Explain encapsulation principle.

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now