(注:このブログはもう更新していません)この日記は私的なものであり所属会社の見解とは無関係です。 GitHub: takahashikzn

[クラウド帳票エンジンDocurain]

結合度と凝集度

f:id:takahashikzn:20140919183640p:plain


いま書いているコードで、結合度という概念が必要だったのでCouplingという単語を使いました。


ただ、カップリングと言うとほら…何というか日本語圏だとアレじゃないですか。
A × Bみたいな。
何のことを言っているかわからないというアナタ、ずっとそのピュアなままのアナタでいて下さい。


というわけで代用品としてCohensionはどうか?と思い、
お馴染みのStackOverflowで検索してみたところ、ナイスな回答を見つけたのでご紹介。


http://stackoverflow.com/questions/39946/coupling-and-cohesion

I'm trying to boil down the concepts of coupling and cohesion to a concise definition. Can someone give me a short and understandable explanation (shorter than the definitions on Wikipedia here and here)? How do they interact?

私は、結合と凝集という2つの概念を簡潔にしようと試みているところです。
どなたか、短くてわかりやすい説明を頂けませんか?(Wikipediaこれとかこれより短いやつでお願いします)
この2つはどう関係しているんですか?

Coupling
  • Loose: You and the guy at the convenience store. You communicate through a well-defined protocol to achieve your respective goals - you pay money, he lets you walk out with the bag of Cheetos. Either one of you can be replaced without disrupting the system.
  • Tight: You and your wife.
Cohesion
  • Low: The convenience store. You go there for everything from gas to milk to ATM banking. Products and services have little in common, and the convenience of having them all in one place may not be enough to offset the resulting increase in cost and decrease in quality.
  • High: The cheese store. They sell cheese. Nothing else. Can't beat 'em when it comes to cheese though.
結合
  • 【疎】君とコンビニ店員の関係。君はごく一般的な手順により目的を果たす。つまり、君は代金を支払い、店員はチートスの入った袋を渡して君を送り出す。これは誰がやっても同じ結果になる。
  • 【密】君と、君の嫁の関係。
凝集
  • 【低】コンビニ。例えば君はコンビニへ、ガソリンを入れたり、牛乳を買ったり、ATMを利用したりするために行く。コンビニには様々なモノやサービスが一箇所にまとまっていて便利な代わりに、値段が高くついて品質が低くなる。
  • 【高】チーズ屋。チーズ屋はチーズを売る。他には何もない。ただしチーズに関しては鉄板だ。