File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

coupling and cohesion

 
karthika gkumar
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

what is coupling? what is cohesion?
i cant understand clearly those things in K&B book
please explain
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check the JavaRanch naming policy, which requires a "last name" longer than "k".

Coupling means that the "internals" of one class are bound to the workings of another. If you have a public field "f" in class Foo and an object myFoo, then an object of another class can say

... = myFoo.f;

or

myFoo.f = ...

That represents tight coupling. It means the fields of the class become part of its public interface; you can't change the fields without "breaking" the code of another class.
If you make that field private, then it can only be accessed via get or set methods or other methods, and that reduces coupling. You can also put controls in these methods to restrict access even more.
Coupling is usually (as Sellars and Yeatman would have said) a Bad Thing.

Cohesion is generally a Good Thing.
It means that a class does one thing and does it well and it doesn't try to do something else. It means that a class keeps its private details hidden (data hiding and encapsulation) and other classes don't need to know how they work. It means there is no access to the internals of the class, only "results" in the form of return values from methods.
Or it means something rather like that.
 
Katrina Owen
Sheriff
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi gk,

Please check your private messages for a message from the staff.

Best regards,
Katrina
 
karthika gkumar
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i changed my display name
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic