This is not a Wikipedia article: It is an individual user's work-in-progress page, and may be incomplete and/or unreliable. For guidance on developing this draft, see Wikipedia:So you made a userspace draft. Find sources: Google (books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
In computer science, data encapsulation or simply encapsulation is the application of the principle of information hiding, whereby certain design information is hidden from the users of an abstraction.
History
editInformation hiding principle
editThe concept of "information hiding" was described in 1971 by David Parnas, who proposed that access to information should be restricted by design in order to reduce the interconnectedness of a system. He described three apparently conflicting design concerns: the desire to have a user-friendly external interface, the desire to reduce development time by splitting a system into modules which can be designed independently, and the desire to easily change the implementation details of a system; he suggested that these concerns could more easily be reconciled if design information were not accessible to everyone. He proposed that programmers should not be responsible for deciding which information to use, but instead system designers should restrict the information that is available to programmers. In the appendix to the article, he gave an example of how to document a module with a formal interface definition so as to hide implementation details from the user.[1]
In 1972, Parnas showed how information hiding can be used as a design criterion for dividing a system into modules. By defining the interfaces between modules such that they hide design decisions from each other, he suggested that a system can support a wider range of functionality without having to change the interface definitions. He noted that care must be taken to ensure that decomposing a system in this way does not negatively impact efficiency.[2]
Data encapsulation
editThe term "encapsulation", or more specifically "procedural encapsulation", was used in 1973 by Stephen Zilles to describe how procedures can be used to encapsulate or "isolate" the underlying representation of a data type. He noted that by using encapsulation:[3]
- the operations defined on a type can be formalized to ensure the correctness of objects of that type;
- modules have to make minimal assumptions about other modules to which they have access; and
- encapsulated data is protected from both accidental and malicious modification.
In the same year, Barbara Liskov and Zilles attempted to formalize the concept of an abstract data type in the context of what would become the programming language CLU, describing the concept of an object (which they also referred to as a "function cluster" or "cluster" for short) as the embodiment of "a data type being completely characterized by the operations on that type". They emphasised that external users view objects as indivisible while the objects may be internally composed of more primitive elements, and referred to abstract data types "encapsulat[ing]" their constituent components.
In 1974, William Wulf outlined the details of the Alphard programming language. He cites the overabundance of "implicit abstractions" – implementation details such as data structures and control flow mechanisms – and the lack of "explicit abstractions" – meta-level abstractions such as procedures and macros – in programming languages at the time, as one of the motivations for his proposals. He describes how Alphard allows certain names to be selectively "exported" from an abstract data type (a "form" in Alphard parlance) so that they are available for use with instances of the type.[4]
In 1974, Lawrence Flon described encapsulation as relating to the operations defined for a type, and as referring to "the collection of all information relevant to a particular implementation". He described three different categories a language may fall into regarding encapsulation:
- operations are bound to a definition of a type;
- operations are bound to an instance of a type (an object); or
- operations are bound to neither a definition nor an instance of a type.
He described the issue of "exportation" – controlling which names are visible to users of a type – as relating to the concept of information hiding, noting that no existing languages yet supported exportation features. He also referred to the CLU and Alphard papers as "proposal[s] for encapsulation".[5]
In 1975, Liskov used the term "encapsulation" to describe the definition of a type so that objects of that type may be manipulated using only specific programmer-defined operations, and the representation of an object is not visible outside of the definition of its type. She referenced CLU and Alphard as programming languages being developed with support for type-checking mechanisms for enforcing encapsulation. She described how encapsulating type definitions simplifies specifications by reducing the amount of information they contain, as well as improving the provability of a program in two regards:[6]
- Assumptions can be made about the implementation of a type since its representation can only be modified via the defined operations.
- Code that uses the type can be reasoned about without having knowledge of the representation of the type.
In the same year, Parnas discussed how attempting to deal with errors at the point where they occur violates the "information hiding principle"; he suggests that interfaces between modules should be designed to communicate information about errors, error handling, and assumptions.[7]
In 1976, Theodore Linden described how abstract data types can be used to encapsulate or "protect" the data representation of an object by allowing direct access only through procedures which are defined as part of the same type. Linden suggested that encapsulation is important when:
- "the data has a complex structure";
- "the data might get into an inconsistent state"; or
- "the data needs to be protected for reasons of privacy or security".
He noted that encapsulation using abstract data types can be used to enforce additional structure as well as to allow redundancy for error detection and recovery. He observed that abstract data types are preferable to procedures as a unit of modularity due to their ability to encapsulate non-global persistent state.[8]
In the same year, William Wulf et al. described encapsulation as the separation of the implementation of an abstraction from its use in an abstract program; they described how the programming language Alphard used an abstraction mechanism to allow encapsulation through information hiding, by making all representational data inaccessible and allowing access only to properties defined in a formal specification.[9]
In the same year, Parnas et al. described how programming languages that support abstract data types enable the programming methodology of information hiding.[10]
In 1978, Wolfram Bartussek and Parnas described "encapsulation" and "data abstraction" as being synonymous with the "information hiding principle"; they describe encapsulation as the design of subtasks which hide their details from the rest of the system, and note that the interface description should define only the requirements that a component must satisfy, terming this the "specification". They suggest that to ensure trouble-free development, specifications should be verifiable for consistency and completeness.[11] In a different paper in the same year, Parnas suggested that "encapsulation", "information hiding" or "abstraction" is intended to isolate abstract components of a system using interfaces which are insensitive to change, so that as far as is possible, the presence or absence of a component is hidden from other components. He noted that this is necessary because software lacks the generality of a mathematical proof, and must be tailored to the situation at hand.[12]
Object-oriented programming
editIn 1980, the first implementation of the programming language C++ included public and private access control allowing data to be encapsulated within a class.[13][14]
In 1982, Tim Rentsch referred to "intelligence encapsulation" – "view[ing] objects from outside to provide a natural metaphor of intrinsic behaviour" – as the first principle of object-oriented programming. He described object-oriented programming as being related to abstract data types, data encapsulation, information hiding and modularization, and noted that the programming languages Alphard, Ada and CLU are designed with a focus on data encapsulation.[15]
In 1984, Albert Cohen looked at the concepts of data abstraction and data encapsulation in the context of object-oriented programming. He described both concepts as referring to the localization and concealment of implementation details, but drew a distinction saying that abstraction refers to classes, whereas encapsulation refers to objects. Cohen went on to state that object-oriented programs are those in which all data structures are encapsulated. Further, he suggests that the principle of information hiding states that it should not be necessary to consider, or possible to access, inessential details, and that encapsulation enforces this for objects.[16]
In 1985, Mark Stefik and Daniel Bobrow discussed the distinction between "strict encapsulation", where a language restricts access to the instance variables of an object, and encapsulation by convention. They note that proponents of strict encapsulation argue that limiting knowledge of an object's internal representation keeps problems concerning the object's state well-bounded. They define encapsulations as the principle that "users of objects ought not have privileged access to the internals of those objects".[17]
In 1986, Alan Snyder discussed the interaction between encapsulation and inheritance. He defines encapsulation as "a technique for minimizing interdependencies among separately-written modules by defining strict external interfaces", and suggests that a module is encapsulated if it can only be accessed via its external interface, and that programming languages support encapsulation by allowing minimal external interfaces to be defined and enforced so that a module can be modified without affecting its users. He states that encapsulation, while making programs easier to understand, maintain and modify – benefits which are especially important for large systems and long-lived data – is severely compromised by inheritance. Allowing subclasses access to the instance variables of a superclass compromises encapsulation. He also noted that languages could provide an additional level of visibility, since the interface designed for descendants of a class may not be suitable for users of instances of the class. He noted that the visibility of inheritance restricts modification of an inheritance hierarchy, and is thus an encapsulation issue, suggesting that it is important to allow inheritance without users of a class knowing about it. He further suggested that inheritance should not form part of the external interface of a class, and that a class should be considered a subtype of another class if it meets its external interface. Interfaces should be defined separately. He also noted that in C++ modules are encapsulated rather than individual objects, since objects of the same type can access each other's internals.[18] In the same year, protected access control was added to C++, allowing separate interfaces to be defined for subclasses.[13][14]
In 1987, Josephine Micallef described encapsulation as "the strict enforcement of information hiding". She listed three levels of encapsulation that can be provided by a programming language: the interface provided to instantiating clients, the interface provided to inheriting clients, and the visibility of inheritance. She noted that many languages at the time did not have good support for encapsulation with inheritance, as they did not allow parts of the interface to be exposed only to inheriting clients, and also did not distinguish between "logical" and "physical" inheritance hierarchies, meaning that inheritance of interface required inheritance of implementation.[19] In the same year, Snyder suggested that object-oriented programming is "any form of programming that exploits encapsulation".[20]
In 1988, Peter Sanderson and Lawrence Rose described encapsulation and inheritance as central to object orientation, and described encapsulation as "the modeling of system elements so that only the specification of their structure and behavior is visible to the modeler" noting that it contributes to modularity and data hiding. He said that encapsulation is provided through the class construct in C++.[21] In the same year, Karl Lieberherr and Ian Holland encoded the idea of encapsulation in the Law of Demeter, which . They noted that application of the law makes software maintenance easier, especially when changes are made at a high rate, but that greater levels of encapsulation come at the cost of greater numbers of methods and arguments, speed of execution, and sometimes code readability.[22]
In 1989, Rebecca Wirfs-Brock and Brian Wilkerson advocated and provided an approach for maximizing encapsulation, noting encapsulation as the main form of abstraction by which complexity is managed in object-oriented programming. They stated that the full benefit of object-oriented programming can only be achieved with encapsulation as a goal of the design process. They describe abstract data types as the "encapsulation of data and the algorithms that operate on that data". They describe encapsulation as the key to making software more resuable, refinable, testable, maintainable and extensible, and suggest that encapsulation can be increased by taking a responsibility-driven as opposed to a data-driven approach to object-oriented design, using a client-server model to focus on the responsibilities of each class rather than the structure of the system, allowing implementation decisions to be postponed to the implementation stage.[23] In the same year, Malcolm Atkinson et al. discussed encapsulation in the context of object-oriented database systems, and stated that encapsulation addresses the need to cleanly separate specification and implementation, as well as the need for modularity in order to aid application structure and for protection and authorization. They described encapsulation as coming from the idea of abstract data types, where the interface is the visible part of an object and the implementation comprises the data and procedures which operate on that data. They noted that in a relational database system, the separation of interface from implementation is not as clear cut, but that encapsulation can be achieved if database records are manipulated using operations that are also stored in the database.[24]
In 1990, Peter Wegner defined encapsulation as the "strong protection [of data] against external access", noting that strong encapsulation comes at the cost of modularity and reusability. He observed that generic functions which can operate on multiple data types are more flexible, but weaken encapsulation and security and can result in unmanageable data structures. He suggested that encapsulation is just one of many trade-offs that must be made by software engineers between structure and flexibility. He noted data abstraction is concerned with encapsulation. He also noted that encapsulation is even more important in concurrent systems than in sequential programs, describing the abstraction boundary as the unit of encapsulation.[25] In the same year, Mary Rosson and Sherman Alpert investigated the cognitive consequences of object-oriented design, and noted that encapsulation allows designers to chunk the object space, simplifying their mental representation of an evolving design.[26]
In 1994, Fernando Brito e Abreu and Rogério Carapuça devised the Metrics for Object-Oriented Design (MOOD) designed to measure the quality of object-oriented software. Two of the metrics – the Method Hiding Factor (MHF) and Attribute Hiding Factor (AHD) – were designed to measure the degree to which methods and attributes within a class are encapsulated.[27]
In 1995, Clark Archer and Michael Stinson, in the context of object-oriented software, defined encapsulation as the "process of bundling together the elements of an abstraction that constitute its structure and behavior" and information hiding as the "process of hiding the structure of an object and the implementation details of its methods".[28]
In 1996, Abreu and Walcélio Melo investigated the ability of the MOOD metrics to predict defects within a system, and found that the MHF was moderately correlated with defects density and severity, but that the AHF was not significantly correlated. They noted that encapsulation mechanisms support information hiding by allowing components to be turned into black boxes thereby reducing side-effects.[29]
In 1997, Rachel Harrison et al. described encapsulation as synonymous with information hiding, and listed it as one the three key elements of object-oriented software alongside abstraction and inheritance. They noted that friend classes in C++ allow encapsulation to be violated, recommending that they be used with care.[30]
In 1998, Harrison et al. noted that data encapsulation or encapsulation is often understood to be "the power of a language to hide implementation details" by use of modules or opaque types. In contrast, they defined information hiding as "the extent to which methods and attributes are visible to code in other classes". They claimed that information can be hidden without being encapsulated and vice-versa.[31] In the same year, Bjarne Stroustrup noted that object-oriented programming is often described as "encapsulation plus polymorphism plus inheritance", but noted that Simula 67 showed that object-oriented programming could be done without encapsulation.
In 2000, Scott Meyers discussed how the use of non-member functions in C++ increases encapsulation as it reduces the amount of code that can see the implementation details of a class. He thus recommended that class interfaces should be minimal, containing no methods which could be implemented as non-member functions. However, he also noted that encapsulation is just one of many competing concerns in interface design, and that minimal class interfaces are not always the best. He notes that encapsulation is desirable because it yields increased flexibility and robustness. He describes a data structure with only public data members as being unencapsulated. He suggests that there can exist different degrees of encapsulation, and that the degree to which a piece of code is encapsulated is determined by the amount of code that would be broken if it were changed. He notes that a public interface is used by an unknowably large amount of other code, and so is completely unencapsulated. He also notes that [32]
In 2001, William Paul Rogers suggested that encapsulation simply describes the language feature that allows bundling of data with methods that operate on the data, and is distinct from information hiding, which is a design principle that aims to protect classes from the implementation details of other classes. He noted that encapsulation does not guarantee, but does facilitate, information hiding, and plays no role in controlling access to internal data.[33]
References
edit- ^ Parnas, D. L. (1971-01-01). "Information distribution aspects of design methodology".
{{cite journal}}
: Cite journal requires|journal=
(help) - ^ Parnas, David Lorge (1972-12-01). "On the Criteria to Be Used in Decomposing Systems into Modules". Commun. ACM. 15 (12): 1053–1058. doi:10.1145/361598.361623. ISSN 0001-0782.
- ^ Zilles, Stephen N. (1973-01-01). "Procedural Encapsulation: A Linguistic Protection Technique". Proceeding of ACM SIGPLAN - SIGOPS Interface Meeting on Programming Languages - Operating Systems. New York, NY, USA: ACM: 142–146. doi:10.1145/800021.808305.
- ^ Wulf, William A. (1974-04-30). "ALPHARD: Toward a Language to Support Structured Programs".
{{cite journal}}
: Cite journal requires|journal=
(help) - ^ Lawrence, Flon, (1974-01-01). "A survey of some issues concerning abstract data types".
{{cite journal}}
: Cite journal requires|journal=
(help)CS1 maint: extra punctuation (link) CS1 maint: multiple names: authors list (link) - ^ Liskov, Barbara H. (1975-07-01). "Data Types and Program Correctness". SIGPLAN Not. 10 (7): 16–17. doi:10.1145/987305.987309. ISSN 0362-1340.
- ^ Parnas, D. L. (1975-01-01). "The Influence of Software Structure on Reliability". Proceedings of the International Conference on Reliable Software. New York, NY, USA: ACM: 358–362. doi:10.1145/800027.808458.
- ^ Linden, Theodore A. (1976-01-01). "The Use of Abstract Data Types to Simplify Program Modifications". Proceedings of the 1976 Conference on Data : Abstraction, Definition and Structure. New York, NY, USA: ACM: 12–23. doi:10.1145/800237.807113.
- ^ Wulf, W. A.; London, R. L.; Shaw, M. (1976-07-01). "An Introduction to the Construction and Verification of Alphard Programs". IEEE Trans. Softw. Eng. 2 (4): 253–265. doi:10.1109/TSE.1976.233830. ISSN 0098-5589.
- ^ Parnas, D. L.; Shore, John E.; Weiss, David (1976-01-01). "Abstract Types Defined As Classes of Variables". Proceedings of the 1976 Conference on Data : Abstraction, Definition and Structure. New York, NY, USA: ACM: 149–154. doi:10.1145/800237.807133.
- ^ Bartussek, Wolfram; Parnas, David Lorge (1978-01-01). "Using Assertions About Traces to Write Abstract Specifications for Software Modules". Proceedings of the 2Nd Conference of the European Cooperation on Informatics: Information Systems Methodology. London, UK, UK: Springer-Verlag: 211–236. ISBN 3540089349.
- ^ Parnas, David L. (1978-01-01). "Designing Software for Ease of Extension and Contraction". Proceedings of the 3rd International Conference on Software Engineering. ICSE '78. Piscataway, NJ, USA: IEEE Press: 264–277.
- ^ a b Stroustrup, Bjarne (1996-01-01). Bergin, Thomas J., Jr.; Gibson, Richard G., Jr. (eds.). History of Programming languages—II. New York, NY, USA: ACM. pp. 699–769. ISBN 0201895021.
{{cite book}}
: CS1 maint: multiple names: editors list (link) - ^ a b ECOOP ! (2015-08-13), Bjarne Stroustrup - Object Oriented Programming without Inheritance - ECOOP 2015, retrieved 2016-09-14
- ^ Rentsch, Tim (1982-09-01). "Object Oriented Programming". SIGPLAN Not. 17 (9): 51–57. doi:10.1145/947955.947961. ISSN 0362-1340.
- ^ Cohen, A. Toni (1984-01-01). "Data Abstraction, Data Encapsulation and Object-oriented Programming". SIGPLAN Not. 19 (1): 31–35. doi:10.1145/948415.948418. ISSN 0362-1340.
- ^ Stefik, Mark; Bobrow, Daniel G. (1985-12-15). "Object-Oriented Programming: Themes and Variations". AI Magazine. 6 (4): 40. doi:10.1609/aimag.v6i4.508. ISSN 0738-4602.
- ^ Snyder, Alan (1986-01-01). "Encapsulation and Inheritance in Object-oriented Programming Languages". Conference Proceedings on Object-oriented Programming Systems, Languages and Applications. OOPSLA '86. New York, NY, USA: ACM: 38–45. doi:10.1145/28697.28702. ISBN 0897912047.
- ^ Micallef, Josephine (1987-08-01). "Encapsulation, reusability and extensibility in object-oriented programming languages" – via Columbia University Academic Commons.
{{cite journal}}
: Cite journal requires|journal=
(help) - ^ Snyder, Alan (1987-01-01). Shriver, Bruce; Wegner, Peter (eds.). Inheritance and the development of encapsulated software systems. Cambridge, MA, USA: MIT Press. pp. 165–188. ISBN 0262192640.
- ^ Sanderson, D. Peter; Rose, Lawrence L. (1988-01-01). "Object-oriented Modeling Using C++". Proceedings of the 21st Annual Symposium on Simulation. ANSS '88. Los Alamitos, CA, USA: IEEE Computer Society Press: 143–156. ISBN 0818608455.
- ^ Lieberherr, K.; Holland, I.; Riel, A. (1988-01-01). "Object-oriented Programming: An Objective Sense of Style". Conference Proceedings on Object-oriented Programming Systems, Languages and Applications. OOPSLA '88. New York, NY, USA: ACM: 323–334. doi:10.1145/62083.62113. ISBN 0897912845.
- ^ Wirfs-Brock, R.; Wilkerson, B. (1989-01-01). "Object-oriented Design: A Responsibility-driven Approach". Conference Proceedings on Object-oriented Programming Systems, Languages and Applications. OOPSLA '89. New York, NY, USA: ACM: 71–75. doi:10.1145/74877.74885. ISBN 0897913337.
- ^ Atkinson, Malcolm; DeWitt, David; Maier, David; Bancilhon, François; Dittrich, Klaus; Zdonik, Stanley (1992-01-01). Bancilhon, François; Delobel, Claude; Kanellakis, Paris (eds.). The object-oriented database system manifesto. San Francisco, CA, USA: Morgan Kaufmann Publishers Inc. pp. 1–20. ISBN 1558601694.
- ^ Wegner, Peter (1990-08-01). "Concepts and Paradigms of Object-oriented Programming". SIGPLAN OOPS Mess. 1 (1): 7–87. doi:10.1145/382192.383004. ISSN 1055-6400.
- ^ Rosson, Mary Beth; Alpert, Sherman R. (1990-12-01). "The Cognitive Consequences of Object-oriented Design". Hum.-Comput. Interact. 5 (4): 345–379. doi:10.1207/s15327051hci0504_1. ISSN 0737-0024.
- ^ Brito e Abreu, Fernando; Carapuça, Rogério (1994). "Object-Oriented Software Engineering: Measuring and Controlling the Development Process".
{{cite journal}}
: Cite journal requires|journal=
(help) - ^ Clark, Archer,; Michael, Stinson, (1995-01-01). "Object-Oriented Software Measures".
{{cite journal}}
: Cite journal requires|journal=
(help)CS1 maint: extra punctuation (link) CS1 maint: multiple names: authors list (link) - ^ Abreu, Fernando Brito e.; Melo, Walcelio (1996-01-01). "Evaluating the Impact of Object-Oriented Design on Software Quality". Proceedings of the 3rd International Symposium on Software Metrics: From Measurement to Empirical Results. METRICS '96. Washington, DC, USA: IEEE Computer Society: 90–. ISBN 0818673648.
- ^ Harrison, R.; Counsell, S.; Nithi, R. (1997-01-01). "An Overview of Object-Oriented Design Metrics". Proceedings of the 8th International Workshop on Software Technology and Engineering Practice (STEP '97) (Including CASE '97). STEP '97. Washington, DC, USA: IEEE Computer Society: 230–. ISBN 0818678402.
- ^ Harrison, R.; Counsell, S.J.; Nithi, R.V. (1998-07-01). "An evaluation of the MOOD set of object-oriented software metrics". IEEE Transactions on Software Engineering. 24 (6): 491–496. doi:10.1109/32.689404. ISSN 0098-5589.
- ^ Meyers, Scott (2000-02-01). "How Non-Member Functions Improve Encapsulation". Dr. Dobb's. Retrieved 2016-09-14.
- ^ Rogers, William Paul (2001-05-18). "Encapsulation is not information hiding". JavaWorld. Retrieved 2016-09-14.