Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

'Cohesive classes reduce coupling'

So, if cohesive classes or connected classes reduce coupling (union), which piece of the puzzle is missing me?

BTW, I took this sentence from an article about identifying classes before any developmemt, which I'm trying to figure out the whole sense of why, when, how to use 'that' particular classes, polymorphism, abstraction, etc.

For sure I'm in the beginner stage about OOD. I have read some books but I don't understand the relationship between cohesion and coupling.

share|improve this question
    
    
@gnat Actually I believe the purpose of the question is to answer how cohesion reduces coupling rather than asking for OOD resources. –  m3th0dman Aug 6 '13 at 6:53
    
@m3th0dman my note relates to 1st revision question, prior to your edits: "could you tell in a correct order which books people need to follow blah blah" –  gnat Aug 6 '13 at 7:00
    
@gnat Before I edited, the question I believe it was something like this: "does this statement hold true?" Anyway, it still asks two distinct questions in one message. –  m3th0dman Aug 6 '13 at 8:11
    
My apologizes, I made two different questions to show how much perception I (don't) have about OOD. –  John Smith Optional Aug 6 '13 at 16:19

2 Answers 2

up vote 5 down vote accepted

It is not contradictory; it's actually a pretty basic idea in OOD. Most of OOD principles relate to one another.

Cohesion relates to how well a given functionality is modeled in a system; if that functionality is only implemented in a single module, then that module is highly cohesive. On the other hand, if a certain functionality is scattered among many modules, then those modules have a weak cohesion. As a concrete example on measuring the cohesion of a class, consider a maximum cohesive class one that uses all its instance fields in all the methods. However in practice this is not always achievable nor desirable.

Coupling derives from how many interconnections are between modules and how strong those interconnections are. If modules heavily rely on one another then a change in a module leads to change in multiple modules.

As a relation between them if a functionality is represented by multiple modules (cohesion) then those modules are tightly coupled in order to achieve that functionality. This also relates to Single Responsibility Principle (and many other principles) which states that only one modules should have only one reason to change, leading to the idea that one module should have one functionality.

As OOD reference book I recommend Object Oriented Analysis and Design by Grady Booch et al.

share|improve this answer

It's not contradictory at all.

Cohesion is about how focused the responsibilities of a given module (or class) are. The more focused, the more cohesive. A class that does only one thing is the most cohesive of all. And it's likely to be coupled to (dependent on) very few other classes, if any.

A class that is less cohesive (in other words, it has more and varied responsibilities) is likely to be coupled to many other classes. Less cohesion, more coupling.

The gist of the 'cohesive classes reduce coupling' phrase is to say that if you build smaller, focused modules, each of them will likely be less coupled than larger, less focused modules. More cohesion allows for more flexibility when composing your modules.

share|improve this answer
    
Simple and rich explanation. Thanks. –  John Smith Optional Aug 6 '13 at 16:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.