Encapsulation

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Ebybymic (Talk); changed back to last version by Matthew Harward)
 
(5 intermediate revisions by 3 users not shown)
Line 2: Line 2:
  
 
In the context of computer science, this term means the logical separation of a concept from another. Often this is related to the [[Information hiding|hiding of information]] behind a defined interface.
 
In the context of computer science, this term means the logical separation of a concept from another. Often this is related to the [[Information hiding|hiding of information]] behind a defined interface.
 +
 +
There are two important parts to encapsulation:
 +
* Decomposing a system into small, self-contained chunks such as packages and classes. This makes the complexity of the system more manageable because developers can look at just one chunk at a time.
 +
* Hiding the internal details of one chunk from the rest of the system ([[Information hiding]]).
  
 
In OO design, this term takes on a stronger meaning. Not only is encapsulation from the user, other computing entities or even other programs, but also within programs themselves.
 
In OO design, this term takes on a stronger meaning. Not only is encapsulation from the user, other computing entities or even other programs, but also within programs themselves.
Line 10: Line 14:
 
* Hybrid Encapuslation (Any form of blend between class and object encapsulation)
 
* Hybrid Encapuslation (Any form of blend between class and object encapsulation)
 
* Limited/no encapsulation  
 
* Limited/no encapsulation  
 +
 +
Encapsulation provides a number of benefits, including:
 +
* The system is easier to understand and modify because it is broken up into small and manageable chunks.
 +
* If data is hidden inside its class, this means that the class that owns the data is in control of the data and it cannot be inadvertently changed by other classes.
 +
* If data is hidden inside its class, the class can enforce validity checks to ensure the data doesn't get into an invalid state.
 +
* If the internal details of a chunk change, the rest of the system will not be affected because it is not dependent on the internal details that have changed.
  
 
== External References ==
 
== External References ==
Line 21: Line 31:
 
* [[Encapsulate concrete state pattern]]
 
* [[Encapsulate concrete state pattern]]
 
* [[Information hiding]]
 
* [[Information hiding]]
 +
* [[Access levels]]
  
 
{{Nomenclature}}
 
{{Nomenclature}}
  
 
[[Category: Nomenclature]]
 
[[Category: Nomenclature]]

Latest revision as of 03:22, 25 November 2010

Encapsulation means the enclosing internal features or ideas.

In the context of computer science, this term means the logical separation of a concept from another. Often this is related to the hiding of information behind a defined interface.

There are two important parts to encapsulation:

  • Decomposing a system into small, self-contained chunks such as packages and classes. This makes the complexity of the system more manageable because developers can look at just one chunk at a time.
  • Hiding the internal details of one chunk from the rest of the system (Information hiding).

In OO design, this term takes on a stronger meaning. Not only is encapsulation from the user, other computing entities or even other programs, but also within programs themselves.

In OO design, several different types of encapsulation are proposed:

Encapsulation provides a number of benefits, including:

  • The system is easier to understand and modify because it is broken up into small and manageable chunks.
  • If data is hidden inside its class, this means that the class that owns the data is in control of the data and it cannot be inadvertently changed by other classes.
  • If data is hidden inside its class, the class can enforce validity checks to ensure the data doesn't get into an invalid state.
  • If the internal details of a chunk change, the rest of the system will not be affected because it is not dependent on the internal details that have changed.

External References

See Also


Personal tools