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
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!