aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes coupling and cohesion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "coupling and cohesion" Watch "coupling and cohesion" New topic
Author

coupling and cohesion

sean zang
Ranch Hand

Joined: Apr 22, 2000
Posts: 33
Hi, folks
Does anyone show me what's main difference between Coupling and
Cohesion. Simple class diagram demonstration will be greatly appreciated
many thanks
Laojar Chuger
Ranch Hand

Joined: Dec 20, 2000
Posts: 111
I guess it's difficult to explain these two concepts graphically. The difference is, basically, coupling measures the connections among classes whereas cohesion measures connections inside a class.
John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1449
I'm not sure what "connections inside a class" means. I have seen cohesiveness defined as how related the data and functions of a class are to each other and the class itself. That is, a class which represents a single concept with data that would be reasonably related to that concept and methods that operate on that data or with each other, would be fairly cohesive.
You should strive for classes (or components, which can be a number of classes) that are cohesive and minimize coupling.
John


The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
Laojar Chuger
Ranch Hand

Joined: Dec 20, 2000
Posts: 111
By connection I mean the dependence between two entities. Sorry for not clearly expressed.
Linda Rising
Author
Ranch Hand

Joined: Jan 21, 2001
Posts: 76
Originally posted by sean zang:
Hi, folks
Does anyone show me what's main difference between Coupling and
Cohesion. Simple class diagram demonstration will be greatly appreciated
many thanks

The notions of coupling and cohesion are old ones -- they were created in the 70s by Yourdon and Constantine and they referred to procedural entities in a program. The concepts still apply today because you can talk about modules and a module could be any program entity, including a class.
When a module is created the reason for its existence is called a design decision (David Parnas originated this expression -- also in the 70s). If a module has high cohesion then everything in that module is related to that design decision.
For a given class, ask yourself why you created that class and then ask if everything in the class is related to that reason. If so, then the class has high cohesion -- that's good!
If elements that relate to a given design decision are found in more than one module, then those modules are coupled. The strength of the coupling is determined by the strength of the relationship between the elements of the design decision.
If you create a class and then find that to implement the design decision that was the reason for creating the class you have to put related things in other classes -- then the classes are coupled -- sometimes this is OK but if the relationship is too strong -- this is not good.
Here's a URL with probably more than you want to know about this :-)!
http://www.iam.unibe.ch/~scg/Archive/PhD/moser-phd.pdf

Linda
Yourdon and Constantine have a list of categories to classify coupling and cohesion for procedural languages. I wrote a paper to do the same for object-based languages. I also wrote the book that you could win this week -- The Pattern Almanac!

------------------
Linda Rising
Author of The Pattern Almanac 2000


Linda Rising<br />Author of <a href="http://www.awprofessional.com/title/0201741571" target="_blank" rel="nofollow">Fearless Change</a>
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
Check out an article from javaworld here
[This message has been edited by Rahul Mahindrakar (edited February 01, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: coupling and cohesion