473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

What is encapsulation?

Marshall Cline wrote:

http://www.parashift.com/c++-faq-lit...s.html#faq-7.4

"Preventing unauthorized access
to some piece of information or functionality."

That's *data hiding* -- not encapsulation.
A C struct *encapsulates* data members
but C does not support any mechanism
for hiding the actual data representation
except *opaque* data structures.

"Inheritance can also be used as a form of encapsulation."

Yes, but public inheritance does not "hide" the base class.

"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."

No. It does *not* force the "user" to use the interface.
A determined hacker will find a way to "reach around" the interface
and access the data members directly.
Data hiding is *not* encryption.
It merely prevents unwary application programmers
from *accidently* accessing data members directly.
Sep 13 '05 #1
21 10831
Ohhh... a philisophical question.

Encapsulation is probably best defined as one of the quotes above that
said:
(putting "in a capsule") <--- I like that :)

It's not hiding things from the developer (although that can be part of
it)... and it's not forcing people to use an interface (it's allowing
people to use an interface)

Ultimatley, it's taking an idea, task, or entity and packing it up in
code to make coding other things easier.

Sep 13 '05 #2
E. Robert Tisdale wrote:
No. It does *not* force the "user" to use the interface.
A determined hacker will find a way to "reach around" the interface
and access the data members directly.


Could you please give an example of how a determined coder may "reach
around" the interface?

Regards,
Peter Jansson
Sep 13 '05 #3
Peter Jansson wrote:
E. Robert Tisdale wrote:
No. It does *not* force the "user" to use the interface.
A determined hacker will find a way to "reach around" the interface
and access the data members directly.


Could you please give an example of how a determined coder may "reach
around" the interface?


#define private public

Sep 13 '05 #4
lol... I'll have to try that one of these days :p

Sep 13 '05 #5

"mlimber" <ml*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Peter Jansson wrote:
E. Robert Tisdale wrote:
> No. It does *not* force the "user" to use the interface.
> A determined hacker will find a way to "reach around" the interface
> and access the data members directly.


Could you please give an example of how a determined coder may "reach
around" the interface?


#define private public


If you can do that, it means you have access to the source code.... then you
might as well dive in and change the whole thing :o) or did I miss some
crucial point here?
Sep 13 '05 #6
All you need is access to the header files, not the full source, to do
that.
And any application that wants someone to use an interface has to fork
over the header files.
Otherwise, the interface won't be defined.

Sep 13 '05 #7
mlimber wrote:


#define private public


Can this be prevented if the interface code contains the following?

#ifdef private
#undef private
#endif

Regards,
Peter Jansson
Sep 13 '05 #8
It could, but it would be just as easy to remove that protection code
from any header file.
That would only work if the header files were somehow write protected.

Sep 13 '05 #9
John Fullman wrote:
It could, but it would be just as easy to remove that protection code
from any header file.
That would only work if the header files were somehow write protected.

I agree.

I believe this to be of little importance since the "attacker" still has
access to the headers so that person could easily change private into
public anyway.

Regards,
Peter
Sep 13 '05 #10
Encapsulation is: When you work on a jigsaw puzzle, the
puzzle starts as a pile-o-parts in a big plastic bag.
The bag is encapsulation. As long as nobody gets "frisky"
the bag will only have parts from this puzzle.

Data hiding is if the bag is opaque and you have to reach
in to get parts. This means you can't see if you are grabbing
an edge part or a corner part or a middle part, nor what
colour it is.

Implementation hiding is if the entire bag is behind a barrier,
and to get another part you have to ask your mom. So you
don't even see the bag, nor know how full the bag still is,
nor even that there *is* a bag. Could be a box or one of
those "bingo" machine air-popup things or your cat could
be behind there dragging over another part every time your
mom holds out a cat treat for it. But your mom told you she
will give you another part whenever you ask for one, until
there are no more.
Socks

Sep 13 '05 #11
Peter Jansson wrote:
John Fullman wrote:
It could, but it would be just as easy to remove that protection code
from any header file.
That would only work if the header files were somehow write protected.
I agree.

I believe this to be of little importance since the "attacker"


You are confused about the purpose of data hiding.
Reaching around the interface cannot be considered an "attack"
on the class library or anything else
because it isn't possible for application programmers
to injure anyone but themselves by doing so.
Data hiding (private data members) are more like a "safety handrail"
that helps prevent application programmers for *accidently*
accessing private data members directly.
Abrogating this safety mechanism may be evidence of stupidity
but *not* malice.
still has access to the headers
so that person could easily change private into public anyway.

Sep 13 '05 #12
Hehe... Totally agree, unless the writer of the library left security
holes in private members.
But, more often than not, you are right... that is just shooting
yourself in the foot.

Sep 13 '05 #13

"John Fullman" <jo**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hehe... Totally agree, unless the writer of the library left security
holes in private members.
But, more often than not, you are right... that is just shooting
yourself in the foot.


How about quoting what you're responding to? This isn't a chat room.

-Howard
Sep 13 '05 #14

Howard wrote:
How about quoting what you're responding to? This isn't a chat room.

-Howard


Good point... but up until 30 seconds ago, I didn't know how to quote
someone. They had to go hide it on me. :p

As for my previous post, I was replying to the post above mine. You can
also switch to a tree view to see which message I was replying to.

Sep 13 '05 #15
"John Fullman" <jo**********@gmail.com> writes:
As for my previous post, I was replying to the post above mine.
In my newsreader, there is no post above yours. We're not all (ab)using a
web browser to access Usenet, you know.
You can also switch to a tree view


How would you know if my news reader has a tree view or not, or whether my
computer has a large enough screen to support such a layout? How would you
know if the server I'm connected to has received the post you're replying
to, or if it still retains it?

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Sep 13 '05 #16
>Data hiding (private data members) are more like a "safety handrail"
that helps prevent application programmers for *accidently*
accessing private data members directly.


Nonsense! The standard doesn't define accidents, only the correct
semantics of the c++ programming language. Why speculate on different
uses this language feature might or might not be put into? The
definition is pretty straightword, that's all there is to it. Why
complicate simple things?

Furthermore, abrogating this safety mechanism may invoke undefined
behaviour depending on how the mechanism was abrogated, and what's the
practical difference between stupidity and malice as far as the
correctness of the program is concerned? None, if the program invokes
undefined behaviour the only important question is how to fix it unless
interested in finding who to blame or other off-topic activities.

If the source is modified, well, then it reasonably follows that we are
not talking about the original source at that point and the question is
what the new one looks like. It might be a brilliant design change, not
evidence of stupidity or it might invoke undefined behaviour. The point
is that we don't know, why should anyone pretend that he/she does?

Sep 14 '05 #17
Sherm Pendley wrote:
"John Fullman" <jo**********@gmail.com> writes:
As for my previous post, I was replying to the post above mine.


In my newsreader, there is no post above yours. We're not all (ab)using a
web browser to access Usenet, you know.
You can also switch to a tree view


How would you know if my news reader has a tree view or not, or whether my
computer has a large enough screen to support such a layout? How would you
know if the server I'm connected to has received the post you're replying
to, or if it still retains it?


Spoken like a true C++ programmer.

Sep 14 '05 #18
On 14 Sep 2005 12:42:39 -0700, u.********@gmail.com wrote:
> You can also switch to a tree view


How would you know if my news reader has a tree view or not, or whether my
computer has a large enough screen to support such a layout? How would you
know if the server I'm connected to has received the post you're replying
to, or if it still retains it?


Spoken like a true C++ programmer.


How do you know that?

-dr
Sep 15 '05 #19
"Sherm Pendley" <sh***@dot-app.org> wrote in message
news:m2************@Sherm-Pendleys-Computer.local...
"John Fullman" <jo**********@gmail.com> writes:
As for my previous post, I was replying to the post above mine.


In my newsreader, there is no post above yours. We're not all (ab)using a
web browser to access Usenet, you know.

Which newsreader are you using? Do you use a PDA?
Sep 15 '05 #20
"jimjim" <ne*****@blueyonder.co.uk> writes:
"Sherm Pendley" <sh***@dot-app.org> wrote in message
news:m2************@Sherm-Pendleys-Computer.local...

In my newsreader, there is no post above yours. We're not all (ab)using a
web browser to access Usenet, you know.

Which newsreader are you using? Do you use a PDA?


Gnus. Why?

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Sep 15 '05 #21
"Sherm Pendley" <sh***@dot-app.org> wrote in message
news:m2************@Sherm-Pendleys-Computer.local...
Gnus. Why?

so I wont use it :-P
Sep 16 '05 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: N.Davis | last post by:
I am very new to Python, but have done plenty of development in C++ and Java. One thing I find weird about python is the idea of a module. Why is this needed when there are already the ideas of...
3
by: K.K. | last post by:
Consider the following code: >>>>>>>>>>> // Define an empty class public class ZorgleCollection : Dictionary<string, Zorgle> { } // Somewhere outside ZorgleCollection:
19
by: G.Ashok | last post by:
Hi All, What is your weightage of the 3 characteristics of Object-Oriented Programming i.e. Inheritance, Encapsulation and Polymorphism. for a total of 100% Please quote your values and let's...
5
by: jmsantoss | last post by:
Hi, This is a design question. I have a class named "DataBuffer" that stores some data. After "DataBuffer" is created it can not be modified. All the methods of "DataBuffer" are const as data...
47
by: Roger Lakner | last post by:
I often see operator implemented something like this: class Foo { ... }; class FooList { public: const Foo& operator (unsigned index) const {return array;}; Foo& operator (unsigned index) ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
16
by: utab | last post by:
Dear all, In programming terminology, what is a wrapper and where is it used? Regards
32
by: bluejack | last post by:
Ahoy: For as long as I've been using C, I've vacillated on the optimal degree of encapsulation in my designs. At a minimum, I aggregate data and code that operate on that data into classlike...
16
by: copx | last post by:
I have recently read "Everything you ever wanted to know about C types" by Peter Seebach (1), and learned about incomplete types. Now, I realise the value of encapsulation, but I wonder whether it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.