Glossary · Automation software engineering and architecture
Encapsulation
Also known as: Information hiding
German: Kapselung
In software engineering, encapsulation is the principle of bundling data with the operations that act on it and restricting direct access to that data from outside, so other parts of the program can only interact with a module or object through its defined interface.
- Software engineering
In one sentence
Encapsulation bundles data with its operations and restricts outside access, so others use a module only through its interface.
Example
The internal step counter of a function block is declared private; other code reads the block's state only through its 'State' output, so the internals can change freely.
How it applies
- Engineering: Encapsulation protects a module's internal state from unintended changes. In IEC 61131-3, function block instance data and access specifiers in object-oriented extensions support it; global variables undermine it.
- Maintenance: Encapsulated modules can be refactored internally without affecting callers, which reduces Change propagation. Breaking encapsulation for a quick fix, for example by writing to another block's internal variable from the HMI, creates hidden dependencies.
- Documentation: Document only the public interface for library users and keep internal details in developer documentation. If users need internal values for diagnostics, provide them through an explicit diagnostic interface rather than by exposing internals.
Encapsulation vs. abstraction
Abstraction decides what a module shows to its users; encapsulation enforces that users cannot reach past it. Encapsulation without good abstraction produces a well-protected but awkward interface; abstraction without encapsulation produces an interface that callers can bypass.