Talk:Encapsulation (computer programming)
![]() | Computing Start‑class ![]() | ||||||||||||
|
![]() | Computer science Start‑class High‑importance | ||||||||||||||||
|
Too technical
If you don't already know what encapsulation is, you'll likely not understand a word of this article. Too technical, too preoccupied with OOP. I'm a reasonably experienced developer, and I had to read it slowly to understand anything at all. 213.30.149.61 (talk) 12:09, 9 July 2015 (UTC)
I agree. This definition of Encapsulation is shallow, and addresses it entirely as an OO concern. Information Hiding seems to be the more accurate version. DarkseidX (talk) 11:37, 18 July 2018 (UTC)
Why "orthogonal"
Why is the word "orthogonal" used on about the 9th line of this article? Doesn't it mean "absolutely without influence"? I suspect that even to establish its possibility in this situation would require some heavy-duty theorizing. How about "apparently (or superficially, or tentatively, or ?) independent? -lifeform (talk) 05:37, 21 November 2015 (UTC)
History? Summary!
And then everyone wonder why WP has a bad rep. I came here to look up where Encapsulation was introduced, but I find nothing. Great. --jae (talk) 01:25, 25 November 2015 (UTC)
- Edit the page to add that information. It won't appear by itself. 81.187.215.34 (talk) 18:21, 15 January 2016 (UTC)
Encapsulation is information hiding
Honestly, I was surprised to find that there are two articles covering what I always thought was the exact same thing. Despite what the oft cited JavaWorld article claims, encapsulation and information hiding are synonymous.
I'm not saying there is only one definition, but if you look back to the first real references to the term "encapsulation" in the late 1970s, you see that encapsulation was first used to mean "designing software in such a way as to hide certain details from your clients", i.e. information hiding. In fact, in "Concise Notes on Software Engineering" (1979), the author refers to this paper – the one used by the JavaWorld article to make the distinction between information hiding and encapsulation – as describing "the priciples of encapsulation". This is just one of the more clear examples. Practically every early reference to "encapsulation" describes it as synonymous with information hiding.
Later on, in the late 1980s and early 1990s, as object-orientated programming gained traction, the "encapsulation mechanisms" provided by some OO languages started to become synonymous with encapsulation. That is, to some people "encapsulation" became "bundling data with methods to hide it from clients". Unfortunately, due to the existence of "public" access modifiers (a programming feature designed to break encapsulation), at some point some people started thinking that encapsulation was simply "bundling data with methods", with no reference to information hiding whatsoever. Of course, without encapsulation, "bundling data with methods" is merely syntactic sugar.
This is all my analysis though. If I get the time I will edit the article to indicate that encapsulation is information hiding, and provide many sources to back it up. Hpesoj00 (talk) 21:32, 3 August 2016 (UTC)
- Agreed. This article does a very poor job of articulating what encapsulation really is: internalizing (hiding) implementation details. It does do a fine job of confusing readers by incorrectly suggesting that encapsulation means bundling data with methods; but that concept is actually called Object Oriented Programming. If these concepts were the same, you would not find examples of encapsulation within non-OO languages. This whole article needs major revisions, but in the short-term I'm going to remove the "historical importance" section. This section has never had any citations, much less valid citations. Jamarr81 (talk) 20:34, 6 March 2017 (UTC)
- In the long term, the Encapsulation is not Information Hiding article on JavaWorld is bunk and needs to be removed. It does a fine job at describing how to approach and design Object Oriented Software, but you cannot just given an example of designing OO software and call it encapsulation simply because you used encapsulation to improve the design. This article right now is a horrible reference for new developers that don't know any better. Jamarr81 (talk) 20:34, 6 March 2017 (UTC)
- Agreed that the article, and its conclusions, need to be removed. It's clearly an opinion piece, not consensus; it's even labeled as such by the opening text: "Authors rarely distinguish between the two and often directly claim they are the same. Does that make it so? Not for me." — Preceding unsigned comment added by 75.136.94.104 (talk) 17:03, 13 November 2017 (UTC)
- @Hpesoj00: Thanks for that, I will definitely review what you've compiled in the near future.
- I agree that the JavaWorld article is at odds with common usage of the term prior to its publication. It seems to be the original source of the definition it espouses. Even Parnus, the author of the paper the article cites who coined the term "information hiding" has stated in later papers that "encapsulation" is related or even synonymous to "information hiding". I recall that I found one academic paper that gave a similar definition, but I think I decided that it was not a particularly reliable source, and did not include it in my review. I no longer have access to the academic database that I used for my review, but I do still have all the papers somewhere, so I should check that I wasn't being biased in my omission. Hpesoj00 (talk) 09:22, 7 March 2017 (UTC)
Pseudo-code vs Code examples
I propose replacing the code examples with equivalent pseudo-code to explain the concept. The current examples are too long and very similar. Conversely we could add more examples, and more, and more, and more. I vote we go the other way. A single effective example in pseudo code for the object-oriented case, and perhaps one for the non OO case. I'm open to suggestions and helping with the contribution. Should I be worried that we may be straying into a WP:NOR violation unless we can find an example in literature with permission. Rkedge (talk) 16:24, 28 August 2017 (UTC)
Encapsulation Is Not a Security Feature
"Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties' direct access to them." I take exception to this statement but did not want to simply edit it before getting some feedback. Encapsulation is a design approach to insulate one piece of code from having to know the underlying implementation of another piece of code. To say that it prevents unauthorized access somehow implies (or states outright) that encapsulation prevents bad guys from messing around at the underlying implementation level. But if you can write code that calls existing code, and you can get your code compiled and bound into an executable, and then run that executable in an environment, then the environment is compromised and you can pretty much do anything you want. You are not going to be stopped by a Private declaration.
The linked article on Encapsulation vs. Data Hiding gives excellent examples of the motivation behind this design approach and does not mention security as a motivation. Nor could I find any source that does.
I invite further discussion on this point. 6StringJazzer (talk) 18:46, 11 March 2018 (UTC)
If I'm understanding the article correctly, it really revolves around obfuscation of the internal workings and that's never ever been a valid security strategy. There are always ways to deduce the inner workings if you're willing to tinker at it long enough. Much like the old board game Black Box or the slightly more modern Minesweeper. Keeping people from seeing it directly doesn't prevent people from figuring out what its doing. — Preceding unsigned comment added by 160.2.44.72 (talk) 00:17, 18 January 2022 (UTC)
Too narrowly defined - It's not only OOP and was invented by D.Parnas
This article defines encapsulation to narrowly, mainly from the OOP point of view.
Encapsulation was a concept invented by D.Parnas in 1972 in the context of modular system development and predates OOP. The keys are information hiding. I'm surprised that the full article doesn't mention Parnas and his pioneering work. See trusted SEBOK source.
The term was adopted in the Software Engineering Glossary in 1990. Languages such as Modula-2 or ADA adopted it for in the context of software modules, long before OOP became mainstream.
I'd therefore suggest to rework the introductory paragraph to make it more general and neutral, and perhaps add somewhere a section on the use outside OOP. --Christophe (talk) 15:01, 19 February 2022 (UTC)