Use when applying encapsulation and information hiding principles in object-oriented design. Use when controlling access to object state and behavior.
View on GitHubTheBushidoCollective/han
jutsu-oop
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-oop/skills/oop-encapsulation/SKILL.md -a claude-code --skill oop-encapsulationInstallation paths:
.claude/skills/oop-encapsulation/# OOP Encapsulation
Master encapsulation and information hiding to create robust, maintainable object-oriented systems. This skill focuses on controlling access to object internals and exposing well-defined interfaces.
## Understanding Encapsulation
Encapsulation is the bundling of data and methods that operate on that data within a single unit, while restricting direct access to some of the object's components. This principle protects object integrity and reduces coupling.
### Java Encapsulation
```java
// Strong encapsulation with validation
public class BankAccount {
private String accountNumber;
private BigDecimal balance;
private final List<Transaction> transactions;
public BankAccount(String accountNumber, BigDecimal initialBalance) {
if (accountNumber == null || accountNumber.isEmpty()) {
throw new IllegalArgumentException("Account number required");
}
if (initialBalance.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException("Initial balance cannot be negative");
}
this.accountNumber = accountNumber;
this.balance = initialBalance;
this.transactions = new ArrayList<>();
}
// Read-only access to account number
public String getAccountNumber() {
return accountNumber;
}
// Read-only access to balance
public BigDecimal getBalance() {
return balance;
}
// Defensive copy for collection
public List<Transaction> getTransactions() {
return Collections.unmodifiableList(transactions);
}
// Controlled mutation with validation
public void deposit(BigDecimal amount) {
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
throw new IllegalArgumentException("Deposit amount must be positive");
}
balance = balance.add(amount);
transactions.add(new Transaction(TransactionType.DEPOSIT, amount));
}
// Controlled mutation with business logic
p