Encapsulation
Definition
Encapsulation bundles data and behavior into a single unit and controls which parts are accessible from outside.
In object-oriented and modular systems, interfaces protect internal states and invariants. Encapsulation supports information hiding but is not exactly the same concept.
Simply explained
Like a device in a casing: only the intended controls are accessible from the outside.
Why it matters in practice
Relevant for maintainable components, APIs, and secure state changes.
Example from business
A shopping cart allows addItem and removeItem, but external components do not directly modify its internal totals.
Limits and pitfalls
- Only consider private keywords as encapsulation; return internal mutable structures; build overly broad public interfaces.
Origin & history
Parnas explained information hiding as a criterion for modularization in 1972. Oracle documentation describes data encapsulation based on object state accessible via methods but hidden internally.
Use in mid-sized companies
- Possible application: Combine domain data and permissible changes in software modules and organize their use via defined interfaces.
Frequently asked questions
Is encapsulation the same as abstraction?
No, but closely related. Why protect internal states? So that invariants and changes remain locally controlled.
Sources
- Parnas (1972) · Parnas (1972)
- Programming with Abstract Data Types · Liskov & Zilles (1974), Programming with Abstract Data Types
- What Is an Object? · Oracle Java Tutorials, What Is an Object?
- Primärtextwiedergabe · Parnas (1972), Primärtextwiedergabe
Source verification: 10./11.10.2026.
Editorially reviewed on: