What is encapsulation?
Encapsulation keeps an object’s state and the operations that control that state together, while restricting uncontrolled outside access.
Study 3 Encapsulation and Abstraction with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is encapsulation?
Encapsulation keeps an object’s state and the operations that control that state together, while restricting uncontrolled outside access.
What does abstraction present?
Abstraction presents an object’s important capabilities while omitting unnecessary implementation details.
What is the purpose of information hiding?
Information hiding prevents clients from depending on implementation details that may change, such as a storage system’s database schema.
What does access control define?
Access control defines which code may use a type or member. Common levels include public, private, protected, and internal or package-private.
What visibility principle should a class follow?
Use the narrowest visibility that supports the design. This reduces accidental misuse and limits dependencies on implementation details.
What is a property?
A property provides field-like syntax while allowing custom behavior when a value is read or changed, such as validation or computation.
What is an invariant?
An invariant is a condition that must remain true for every valid object state, such as a date range whose end is not earlier than its start.
How does validation differ from normalization?
Validation rejects unacceptable input; normalization transforms acceptable but variable input, such as trimming surrounding whitespace.
What does valid-by-construction mean?
A valid-by-construction object is valid immediately after successful construction because its required conditions were checked during creation.
Why should a class avoid returning an internal mutable collection?
Returning an internal mutable collection lets callers change private state without following the class’s rules. Use a read-only view, defensive copy, or immutable value instead.
Why should a public interface be minimal?
A smaller public interface is easier to understand, test, document, and change because every public member is a potential client dependency.
What is the difference between a precondition and a postcondition?
A precondition states what callers must provide before an operation can succeed; a postcondition states what success guarantees afterward.