oop-encapsulation
БесплатноБез исполняемых скриптовНе проверенUse when applying encapsulation and information hiding principles in object-oriented design. Use when controlling access to object state and behavior.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
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
// 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
public void withdraw(BigDecimal amount) {
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
throw new IllegalArgumentException("Withdrawal amount must be positive");
}
if (amount.compareTo(balance) > 0) {
throw new InsufficientFundsException("Insufficient balance");
}
balance = balance.subtract(amount);
transactions.add(new Transaction(TransactionType.WITHDRAWAL, amount));
}
}
Python Encapsulation
class Employee:
"""Employee with encapsulated salary information."""
def __init__(self, name: str, salary: float, department: str):
if not name:
raise ValueError("Name is required")
if salary < 0:
raise ValueError("Salary cannot be negative")
self._name = name # Protected attribute
self.__salary = salary # Private attribute (name mangling)
self._department = department
self.__performance_rating = 0.0
@property
def name(self) -> str:
"""Read-only access to name."""
return self._name
@property
def department(self) -> str:
"""Read-only access to department."""
return self._department
@property
def salary(self) -> float:
"""Controlled access to salary."""
return self.__salary
@salary.setter
def salary(self, value: float) -> None:
"""Controlled mutation with validation."""
if value < 0:
raise ValueError("Salary cannot be negative")
if value < self.__salary * 0.9:
raise ValueError("Salary cannot decrease by more than 10%")
self.__salary = value
@property
def performance_rating(self) -> float:
"""Read-only access to performance rating."""
return self.__performance_rating
def update_performance(self, rating: float) -> None:
"""Controlled update with validation and side effects."""
if not 0 <= rating <= 5:
raise ValueError("Rating must be between 0 and 5")
self.__performance_rating = rating
# Business logic: automatic raise for high performers
if rating >= 4.5:
self.__salary *= 1.10
def give_raise(self, percentage: float) -> None:
"""Apply percentage raise with validation."""
if percentage < 0:
raise ValueError("Raise percentage cannot be negative")
if percentage > 20:
raise ValueError("Single raise cannot exceed 20%")
self.__salary *= (1 + percentage / 100)
def __repr__(self) -> str:
return f"Employee(name={self._name}, department={self._department})"
TypeScript Encapsulation
// Class-based encapsulation with private fields
class UserAccount {
readonly #id: string;
#username: string;
#email: string;
#passwordHash: string;
#lastLoginAt: Date | null = null;
#failedLoginAttempts = 0;
#isLocked = false;
constructor(username: string, email: string
Установить oop-encapsulation в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
BashReadFAQ
Что делает скилл oop-encapsulation?
Use when applying encapsulation and information hiding principles in object-oriented design. Use when controlling access to object state and behavior.
Как установить скилл oop-encapsulation?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл oop-encapsulation запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic