Skip to content
Back to skills

Interface Composition Design

ASecurity

クラス設計やアーキテクチャリファクタリング時に使用。継承より合成を推奨。

  • 755 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added February 9, 2026
toolstypescript

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill interface-composition-design --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Interface Composition Design?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Interface Composition Design
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-interface-composition-design/badge)](https://www.skillsdirectory.com/skills/majiayu000-interface-composition-design)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: interface-composition-design
description: クラス設計やアーキテクチャリファクタリング時に使用。継承より合成を推奨。
---

# Interface-based Design

## 📋 実行前チェック(必須)

### このスキルを使うべきか?
- [ ] クラスを設計する?
- [ ] 継承 vs 合成の判断をする?
- [ ] 依存性注入を設計する?
- [ ] リファクタリングで構造改善する?

### 前提条件
- [ ] 変化する部分を特定したか?
- [ ] 依存関係を把握しているか?
- [ ] 単一責任の原則を確認したか?

### 禁止事項の確認
- [ ] 深い継承階層を作ろうとしていないか?
- [ ] 具象クラスに直接依存しようとしていないか?
- [ ] パラメータを追加し続けて爆発していないか?

---

## トリガー

- クラス設計時
- 継承 vs 合成の判断時
- 依存性注入設計時
- リファクタリングで構造改善時

---

## 🚨 鉄則

**実装を隠し、インターフェースのみ公開。合成で拡張。**

---

## 判断基準

### 1. パラメータ爆発していないか?

```typescript
// ❌ パラメータ追加し続ける
process(data, useA: boolean, useB: boolean, useC: boolean, ...)

// ✅ 実装クラスを追加
interface Processor { process(data): Result }
class ProcessorA implements Processor {}
class ProcessorB implements Processor {} // 新規追加
```

### 2. 継承 vs 合成

```typescript
// ❌ 深い継承
class A extends B extends C extends D

// ✅ 合成
class Service {
  constructor(
    private readonly processor: Processor,
    private readonly validator: Validator
  ) {}
}
```

---

## 依存性注入

```typescript
// インターフェースに依存
interface Repository {
  find(id: string): Promise<Entity>;
}

class Service {
  constructor(private readonly repo: Repository) {}
}

// テスト時はモック注入
const mockRepo: Repository = { find: async () => mockEntity };
new Service(mockRepo);
```

---

## 🚫 禁止事項まとめ

- 深い継承階層
- 具象クラスへの直接依存
- パラメータの無限追加
- インターフェースなしの設計

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in tools →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.