Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: Getters and Setters Design

Front

Why might exposing a public getter for sensitive data be risky?

Sensitive data could be accessed and misused. Exposing a public getter for sensitive data, like a password, can…

View Card →
Flashcard Study

Java: Getters and Setters Design

Front

How does immutability support encapsulation?

Immutability prevents changes to the object's state after creation. Immutable objects are fully initialized upon creation and their…

View Card →
Flashcard Study

Java: Getters and Setters Design

Front

Why does validation in setters matter in this design?

To ensure only valid data is assigned to fields. Validation in setters prevents invalid data from corrupting the…

View Card →
Flashcard Study

Java: Getters and Setters Design

Front

Why prefer intentional design over generated boilerplate?

Intentional design ensures the class fits its purpose and maintains integrity. Relying on auto-generated getters and setters can…

View Card →
Flashcard Study

Java: Getters and Setters Design

Front

What are the tradeoffs of a large API surface?

It increases the complexity and maintenance burden. A large API surface can make a class more difficult to…

View Card →
Flashcard Study

Java: Getters and Setters Design

Front

How do domain methods differ from generic setters?

Domain methods encapsulate specific logic, whereas setters do not. Domain methods provide a specific way to interact with…

View Card →
Flashcard Study

Java: Getters and Setters Design

Front

Why might you avoid creating setters for every field?

To maintain control over how and when a field is modified. Not every field needs a setter, especially…

View Card →
Flashcard Study

Java: Getters and Setters Design

Front

When is a getter method reasonable to use?

When you need to provide read access to a field without exposing it directly. Getters are used to…

View Card →
Flashcard Study

Java: Getters and Setters Design

Front

Why are private fields common in Java classes?

To enforce encapsulation by restricting direct access. Private fields are used to protect the internal state of an…

View Card →
Flashcard Study

Java: Getters and Setters Design

Front

Why is a domain method often better than a generic setter?

A domain method can explain the action and validate it more safely. A generic setter like `setStock(...)` exposes…

View Card →