This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes coupling and cohesion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "coupling and cohesion" Watch "coupling and cohesion" New topic

coupling and cohesion

karthika gkumar

Joined: Apr 15, 2008
Posts: 6

what is coupling? what is cohesion?
i cant understand clearly those things in K&B book
please explain
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45301
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;


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

Joined: Nov 03, 2006
Posts: 1367
Hi gk,

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

Best regards,
karthika gkumar

Joined: Apr 15, 2008
Posts: 6
i changed my display name
wood burning stoves
subject: coupling and cohesion
It's not a secret anymore!