Jump to content

Talk:Encapsulation (computer programming)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Too technical

[edit]

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)[reply]

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)[reply]

Why "orthogonal"

[edit]

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)[reply]

History? Summary!

[edit]

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)[reply]

Edit the page to add that information. It won't appear by itself. 81.187.215.34 (talk) 18:21, 15 January 2016 (UTC)[reply]

Encapsulation is information hiding

[edit]

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)[reply]

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)[reply]
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)[reply]
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)[reply]
@Jamarr81: I have compiled what is essentially a chronological literature review here of the concept of encapsulation. I never quite finished it, and have yet to incorporate it into this article because I don't know if it is in an appropriate format for Wikipedia.
@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)[reply]

Encapsulation is not the same as information hiding, though there is some similarity. Take the example of a date and time which is represented internally by a single number, the total number of nanoseconds + or - since January 1, 2000 at 0:00.0 (yes, no system does that, I'm deliberately choosing an example that doesn't exist). This is a perfectly valid way of representing a date/time value. Is such a date/time object hiding the month? Or the day of the year? No. If it provides an interfaces such as dt.year, dt.month, dt.day, does that change anything? Again, no. Could I have two different implementations of date/time classes with the same API, the first which stores nanoseconds since 2000 and the second which stores values for year, month, day, hour, etc. Is the second implementation hiding the total nanoseconds since 2000? Of course not.

RoyLeban (talk) 09:48, 15 December 2022 (UTC)[reply]

Encapsulation can be considered synonymous with information hiding, at least in the early academic literature. Encapsulation can also describe the practical implementation of information hiding, especially in OO programming. Certainly, I don't think they are distinct enough to justify two separate articles. However, it would require significant efforf on the part of someone to combine them and correct all the misinformation. If you are up to the task, you might find the literature review I did a handy reference: User:Hpesoj00/sandbox/Encapsulation. I had hoped to do it myself, but I don't think I ever will now. Hpesoj00 (talk) 14:01, 15 December 2022 (UTC)[reply]
I disagree that they should be one article. There are many, many places on Wikipedia where this mistake is made. Distinct things should have distinct articles. Otherwise, we would just have one gigantic article for Data Structures. RoyLeban (talk) 08:00, 16 December 2022 (UTC)[reply]
It depends entirely on _how_ distinct the topics are from one another. If the two articles end up repeating much of the same information, or one or both of them ends up containing very little information, then there is a case for merging. The terms "encapsulation" and "information hiding", by and large, refer to the exact same concept within computer science: the hiding of design decisions behind an interface in order to reduce the interconnectedness of a system. At most, "encapsulation" may refer to the practical application of information hiding, while "information hiding" may refer to the more abstract concept, but even this doesn't justify two articles IMO.
In your example, the information that is being hidden _is_ the implementation of the date/time type. Any information revealed by the interface is by definition _not_ hidden. The degree to which an interface hides information about the implementation _is_ the degree to which the implementation is encapsulated. An interface that hides no information about the implementation encapsulates nothing. These definitions are backed up by most of the sources in my literature review. The only contradictory source is the article Encapsulation is not Information Hiding mentioned above, but the distinction the author makes is contrary to nearly every use of the terms I could find in the academic literature. In short, (putting my objectivity to one side for a moment) the author seems to have just pulled a new (very OOP-centric) definition out of his rear end. I would like to hear what you think the difference is between encapsulation and information hiding. Hpesoj00 (talk) 15:16, 19 December 2022 (UTC)[reply]
This isn't true: The only contradictory source is the article... It's the only one you're aware of. At a minimum, you also have me, so it is not the case that everybody agrees except for one person. And I've had this opinion for decades before that article was written. You are confusing information with functions (or methods), and you are confusing information with implementation. You are also ignoring the fact that encapsulation can be used in hardware and software which connects to hardware. In short, encapsulation hides how something is implemented, which may or may not include stored data; information hiding hides stored data from users of a system. implementation ≠ data. RoyLeban (talk) 11:24, 22 December 2022 (UTC)[reply]

Pseudo-code vs Code examples

[edit]

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)[reply]

Encapsulation Is Not a Security Feature

[edit]

"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)[reply]

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)[reply]

Too narrowly defined - It's not only OOP and was invented by D.Parnas

[edit]

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)[reply]

Parnas's 1972 paper certainly promoted the term, but it looks like the term predates the paper. A 10-second search on Google books turned up these from earlier: Encyclopedia of Library and Information, NBS Special publication, Congressus Numerantium, and Analysis and Approach to the Development

I don't know who invented the term. Further the idea of hardware encapsulation predates software encapsulation by a long shot, though I don't know about the terminology.

RoyLeban (talk) 10:08, 15 December 2022 (UTC)[reply]

I'm fairly certain that "information hiding" was coined by Parnas, and use of the term "encapsulation" to describe the related ideas came afterwards (see User:Hpesoj00/sandbox/Encapsulation as mentioned in my other reply). But if you can find specific references suggesting otherwise I'd be keen to see them (the links you gave appear to be of publications from after 1971, despite what the Google Books listing says). Hpesoj00 (talk) 14:31, 15 December 2022 (UTC)[reply]
It can be hard to look within books in Google Books (and, yeah, they list dates wrong sometimes), but one of those I found had an internal copyright date of 1970. Another looks like it's dated 1968. Proof either way from 50+ years ago can be hard without access to the physical materials. RoyLeban (talk) 07:57, 16 December 2022 (UTC)[reply]

Inheritance

[edit]

An act in which an object acquires the properties of another existing object is simply known as inheritance for example a laptop combines many components and accessories these components and accessories are manufactured by many companies or organisation does in other words a laptop acquires properties from existing object so it can be called as inheritance similarly child inherit some characteristics from their grandparents and or parents thus it can be said that the child is a class that inherits properties from existing class 2409:4063:4D83:9953:9FD3:DEEB:1B40:48FD (talk) 06:12, 2 July 2022 (UTC)[reply]

INTRODUCTION TO JAVA

[edit]

Javed 3rd generation object oriented programming language with various features for writing programs or codes or applets it has the programmer to develop various software for solving different computational program and also support the program to develop an internet program every programming language consist many commands and statement to control various task the programmer sequence these commands statements according to the problem to be solved further we will study the Java programming language and its features along with the concept that how to develop programs using the bluej IDE (integrated development environment) 2409:4063:4D83:9953:9FD3:DEEB:1B40:48FD (talk) 06:16, 2 July 2022 (UTC)[reply]

TYPES OF JAVA PROGRAM

[edit]

The sequence set of instructions of any programming language used to find the solution of a problem is known as a program a job a program is composed of data members and methods while writing a program in Java the program will specify the data and code to form a class collectively these elements are known as members of the class the data of the class are normally known as member variables or instance variable or data number data used for processing is known as data or data members or variables or instance variables for example ABT by 4 method or function the self contained program structure that uses data or variable of the class produce the required output is known as method or number method or function the Java program is commonly divided into following categories aplet program application program interface or application program the above programming concept are discussed below applet program the Java applet is an application and used to add small interactive components or enhancement to a web page these may consist of buttons is scrolling text or choice option etc and can also be used to display larger programs like word processor or games etc. Another word we can say that the program written in the Java program language that can be included in an HTML (hypertext markup language) page is known as applet program. 2409:4063:4D83:9953:9FD3:DEEB:1B40:48FD (talk) 06:20, 2 July 2022 (UTC)[reply]

Wow this is bad

[edit]

I can't believe how much this article gets wrong. In the first paragraph alone:

In object-oriented programming (OOP),

Not true. Encapsulation can be used with any program paradigm and predates OOP. To some extent, encapsulation was an inspiration for OOP.

encapsulation refers to the bundling of data with the methods that operate on that data,

Poorly worded; makes assumptions about implementation.

or the restricting of direct access to some of an object's components.

Encapsulation is not about restriction; this assumes that object's components exist. As a trivial example, a date might be represented as total milliseconds since 1900 or as (year, month, day, etc.). In the first case, there is no restriction to the year component — it doesn't even exist; in the second case, there is no restriction to the total milliseconds since 1900 — it also doesn't exist. Yet both could provide .year and .totalmilliseconds accessors.

Encapsulation is used to hide the values or state of a structured data object inside a class,

Not true. Assumes that certain values or state exist. See above.

preventing direct access to them by clients

Assumes that certain values exist.

in a way that could expose hidden implementation details

Encapsulation isn't about "hidden implementation details" — it's about providing a consistent and usable interface which is independent of how something is actually implemented.

or violate state invariance maintained by the methods.

Not true. This could be done in other ways without encapsulation. For example, a date value which is simply stored as total milliseconds since 1900 cannot be inconsistent, nor can changing it violate state invariance — it is simply a number. Keeping state consistent can be a big benefit of encapsulation and OOP, but it is not its sole purpose.

RoyLeban (talk) 23:17, 6 July 2022 (UTC)[reply]

I made some changes to improve the intro section, but the entire page needs a lot of work. It reads like it was written by somebody who doesn't really understand encapsulation or OOP. Having a page on encapsulation that doesn't mention Simula, Smalltalk, Lisp, or Flavors is pretty incredible.

RoyLeban (talk) 09:25, 15 December 2022 (UTC)[reply]

I noticed this conflict in definitions when I merged information from another article. But the first sentence has a source. Albeit the verifiability hasn't been checked (and I cannot find any previous discussion about the site's reliability).  AltoStev (talk) 23:39, 3 November 2023 (UTC)[reply]
Nevermind, the source seems to confirm what you said... AltoStev (talk) 23:40, 3 November 2023 (UTC) Edit: Wait what how did I completely misread the article, ignore[reply]

India Education Program course assignment

[edit]

This article was the subject of an educational assignment supported by Wikipedia Ambassadors through the India Education Program.

The above message was substituted from {{IEP assignment}} by PrimeBOT (talk) on 20:12, 1 February 2023 (UTC)[reply]