wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Encapsulation is not information hiding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Encapsulation is not information hiding?" Watch "Encapsulation is not information hiding?" New topic
Author

Encapsulation is not information hiding?

sachin verma
Ranch Hand

Joined: Mar 25, 2008
Posts: 177
The principles of information hiding go beyond the Java language facility for encapsulation
Encapsulation refers to the bundling of data with the methods that operate on that data. Often that definition is misconstrued to mean that the data is somehow hidden. In Java, you can have encapsulated data that is not hidden at all.

please comment on this as I want a more clearer definition of Encapsulation

[ April 25, 2008: Message edited by: sachin verma ]
[ April 26, 2008: Message edited by: Bear Bibeault ]

SCJP || SCWCD

sachin verma
Ranch Hand

Joined: Mar 25, 2008
Posts: 177
Show some interest friends as it is a very basic and important topic

I have heard about encapsulation that
Encapsulation means as much as shielding. Each OO object has a shield around it. Objects can't 'see' each other. They can exchange things though, as if they are interconnected through a hatch.

but it is different from what I posted earlier
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
This is the article you were referring to:

http://www.javaworld.com/javaworld/jw-05-2001/jw-0518-encapsulation.html

Mr. Rogers is trying to make that point that "encapsulation" has more do with with how data is *used*, in contrast to it's visibility.

He further goes on to say that "information hiding" is much more than just making data "private".

This is all true.

I would definitely read the article ... but I wouldn't get too hung up on the terminology. The basic point is:

1. Information hiding is Good

2. Encapsulation is an important part of Information Hiding

PS:
And no, just because you "encapsulate" something, doesn't mean you can't also expose the internals. "What's inside" doesn't necessarily also have to be "hidden". It's just usually smart to hide it :-)
[ April 25, 2008: Message edited by: Paul Santa Maria ]

Paul M. Santa Maria, SCJP
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by sachin verma:
... but it is different from what I posted earlier

I'm not sure it's fundamentally different. I think it's just a slightly different perspective on the same concept.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by sachin verma:
... Show some interest friends as it is a very basic and important topic...

This is a forum, not a chat room, so I don't think 22 minutes is a long time to wait for a response. See JavaRanch FAQ: Ease up.
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
Hey, Sachin -

Marc is correct on both counts.

Also: if you're going to ask a question about something you read somewhere - then be sure to cite where you read it!!!. I shouldn't have needed to Google for the Rogers article - you should have posted a link in your original question.

IMHO .. PSM
[ April 25, 2008: Message edited by: Paul Santa Maria ]
sachin verma
Ranch Hand

Joined: Mar 25, 2008
Posts: 177
thanks next time, I bet ...I will
sachin verma
Ranch Hand

Joined: Mar 25, 2008
Posts: 177
Can anybody explain this completely in simple words and if possible with example...or should I use a new post for it?

Encapsulation is the process of compartmentalizing the elements of an abstraction that constitute
its structure and behavior; encapsulation serves to separate the contractual interface of an
abstraction and its implementation.


reference is Object-Oriented Analysis and Design With Applications 2nd EDITION by Grady booch and page no 56
sachin verma
Ranch Hand

Joined: Mar 25, 2008
Posts: 177
This is a forum, not a chat room, so I don't think 22 minutes is a long time to wait for a response. See JavaRanch FAQ: Ease up.

I have read it and I got it sir...It is something that I was unaware earlier...but now I do and thanks for letting me know
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
Here's a good link (IMHO):
http://www.libertyassociates.com/pages/column2.htm

Well-encapsulated objects act as a "black box" for other parts of the program which interact with it. They provide a service, but the calling objects do not need to know the details how the service is accomplished.


You might encapsulate the abstract concept of "number" by providing operations like "add", "subtract", "multiply", "divide" and "assign" (+, -, *, /, + or =; but just as easily custom methods like plus(), minus(), times(), div() or copy()).

Similarly, you might encapsulate the concept of "string" by providing operations like "concatenate" and "assign" (+ or =, but just as easily methods like contains(), substring(), length(), etc etc)

In the original article by Rogers you cited, he *wasn't* saying that "encapsulation" wasn't closely related "information hiding". Quite the opposite. They are intimately related.

His point was that they are related ... but sometimes programmers might confuse them as being "the same thing". And that, Mr. Rogers was trying to point out, can lead to problems.

Again: "encapsulation" defines what the outside world can do with your object's data. "Information hiding" is a strategy for keeping as much about the object as possible a strict secret from the outside world.

'Hope that helps .. PSM
[ April 26, 2008: Message edited by: Paul Santa Maria ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Encapsulation is not information hiding?