473,702 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

"Inheritanc e 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 10860
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.goo glegroups.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

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

Similar topics

31
2524
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 class, file, and package? To my mind, although one CAN put many classes in a file, it is better to put one class per file, for readability and maintainability. One can then create packages and libraries, using groups of files, one
3
1790
by: K.K. | last post by:
Consider the following code: >>>>>>>>>>> // Define an empty class public class ZorgleCollection : Dictionary<string, Zorgle> { } // Somewhere outside ZorgleCollection:
19
1805
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 discuss how the people thinking about OOP :-) Regards,
5
1677
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 can not be modified after it was created. Up to here everything is fine. The problem is when I want to get clever with data storage. My program has an array of "DataBuffers" that gets pre-allocated. If I want to use that memory instead of...
47
3343
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) {return
669
25984
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
16
3443
by: utab | last post by:
Dear all, In programming terminology, what is a wrapper and where is it used? Regards
32
4206
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 files; but now and then I go on an opaque type joyride, and create minimalist header files that define very clean interfaces. The problem with that is that it prevents some optimizations:
16
2134
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 is proper C style to use that much of it. By using incomplete types you end up with something like this: object_set_colour(object, RED); colour = object_get_colour(object); instead of:
0
8739
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8652
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8983
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8940
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6575
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.