Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encapsulation is not information hiding?

 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks next time, I bet ...I will
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic