凝集度、結合度、関心の分離
コードの保守性を左右する、ソフトウェア設計の3つの基本特性、高い凝集度、低い結合度、明確な関心の分離を身につけます。
「凝集度、結合度、関心の分離」はCoddyKit上の無料Clean Architecture & Design Patterns in Practiceレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはClean Architecture & Design Patterns in Practice学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Clean Architecture & Design Patterns in Practiceコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why These Properties Matter
Under clean code and SOLID lie three deeper design properties: cohesion, coupling, and separation of concerns. They explain why the rules work.
What is Cohesion
Cohesion measures how well a module’s responsibilities belong together. High cohesion = one well-defined job; low cohesion = a grab-bag of unrelated methods.
Low vs High Cohesion
Compare the two: the Util class mixes unrelated concerns, while UserRepository is tightly focused. That focus is high cohesion.
// Low cohesion
class Util {
saveUser() {}
sendEmail() {}
formatDate() {}
}
// High cohesion
class UserRepository {
save() {}
findById() {}
}What is Coupling
Coupling measures how much one module depends on another’s internals. Tight coupling spreads changes everywhere; loose coupling keeps interactions minimal.
Tight Coupling Example
Here OrderService creates its own SmtpMailer, locking it to that exact class. Swapping the mailer means editing the service — tight coupling.
class OrderService {
constructor() {
this.mailer = new SmtpMailer();
}
}Loosening the Coupling
Inject the mailer instead. Now OrderService depends on an abstraction and accepts any implementation. That’s loose coupling.
class OrderService {
constructor(mailer) {
this.mailer = mailer;
}
}The Sweet Spot
The sweet spot is high cohesion and low coupling together: focused modules that stay independent, so systems are easy to change, test, and reason about.
Separation of Concerns
Separation of concerns means splitting a program so each part owns one distinct concern — keep UI, business logic, and data access in separate layers.
Mixed Concerns
This function tangles data access, logic, and presentation together. Touch any one concern and you risk breaking the others — mixed concerns.
function showTotal(id) {
const rows = db.query('SELECT * FROM orders WHERE id=' + id);
const total = rows.reduce((s, r) => s + r.price, 0);
document.body.innerHTML = 'Total: ' + total;
}Separated Concerns
Split it into a repository, a calculator, and a view. Each concern now changes and tests independently. Much cleaner.
const order = repository.findById(id);
const total = calculator.total(order);
view.render(total);How They Connect to SOLID
These properties underpin SOLID: single responsibility drives cohesion, dependency inversion drives low coupling, and layering expresses separation of concerns.
Quick Check
High cohesion, low coupling — can you tell them apart?
Recap
You’ve got the foundations: cohesion keeps related work together, low coupling minimizes dependencies, and separation of concerns divides by purpose.
よくある質問
「凝集度、結合度、関心の分離」レッスンは無料ですか?
はい。「凝集度、結合度、関心の分離」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Clean Architecture & Design Patterns in Practiceコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Clean Architecture & Design Patterns in Practiceコースには全4レッスンが含まれています。
「凝集度、結合度、関心の分離」で何を学びますか?
コードの保守性を左右する、ソフトウェア設計の3つの基本特性、高い凝集度、低い結合度、明確な関心の分離を身につけます。 ブラウザで直接実行するハンズオンコードでClean Architecture & Design Patterns in Practiceを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Clean Architecture & Design Patterns in Practiceを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのClean Architecture & Design Patterns in Practiceは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「凝集度、結合度、関心の分離」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このClean Architecture & Design Patterns in Practiceレッスンでコードを書いて実行できますか?
はい。すべてのClean Architecture & Design Patterns in Practiceレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Clean Code 入門
- SOLID 原則の概要
- 優れた設計の価値
- 凝集度、結合度、関心の分離