471,119 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

data abstraction vs encapsulation example needed

I am a beginner in C++. I come across the terms data abstraction and
encapsulation in C++.
I am unable to understand the definitions.

Kindly explain these terms with a simple example in C++

Thanks
V.Subramanian

Sep 15 '07 #1
1 14071
subramanian100in wrote:
I am a beginner in C++. I come across the terms data abstraction and
encapsulation in C++.
I am unable to understand the definitions.

Kindly explain these terms with a simple example in C++
"Abstraction" means its dictionary definition, which is probably "replace a
complex topic with a simple name, as a convenient reference." That's all it
can mean; there is (thankfully!) no C++ keyword 'abstract'!

Learn the keyword 'virtual', to get with one of C++'s abstracting systems.

"Encapsulation" means each object in a program has a capsule, which is the
set of methods used to operate it. The most trivial example is:

class Foo
{
public:
int getBar();
private:
int Bar;
};

That means the calling code cannot access Bar directly. The class Foo can
therefor maintain Bar, and can ensure that client code always thinks it
contains the correct value. These rules make programs easier to change and
upgrade.

--
Phlip
http://www.oreilly.com/catalog/9780596510657/
"Test Driven Ajax (on Rails)"
assert_xpath, assert_javascript, & assert_ajax
Sep 15 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Uwe Mayer | last post: by
21 posts views Thread by ambika | last post: by
9 posts views Thread by Anand Vardhan | last post: by
2 posts views Thread by DKode | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.