Jump to content

Encapsulation (computer science)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 76.22.74.106 (talk) at 07:07, 5 March 2009 (i call bs). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computer science, Encapsulation is the hiding of the internal mechanisms and data structures of a software component behind a defined interface, in such a way that users of the component (other pieces of software) only need to know what the component does, and cannot make themselves dependent on the details of how it does it. The purpose is to achieve potential for change: the internal mechanisms of the component can be improved without impact on other components, or the component can be replaced with a different one that supports the same public interface.

Encapsulation also protects the integrity of the component, by preventing users from setting the internal data of the component into an invalid or inconsistent state.

Another benefit of encapsulation is that it reduces system complexity and thus increases robustness, by limiting the interdependencies between software components.

The concept of encapsulation is most commonly associated with object-oriented programming, where the interface to an object is defined by its public methods, while its internal state is represented by private data. However, the idea is more general than this: for example, a relational database is encapsulated in the sense that its only public interface is the SQL language, which hides all the internal machinery and data structures of the database management system. As such, encapsulation is a core principle of good software architecture, at every level of granularity.

Encapsulating software behind an interface allows the construction of objects that mimic the behavior and interactions of objects in the real world. For example, road traffic can be simulated by creating objects that mimic the behavior of real vehicles and road junctions. This idea is most prominent in simulation and virtual reality software (for example, games)[citation needed], but it is also important in other fields such as network modeling and computer-aided design.