This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "coupling and cohesion" Watch "coupling and cohesion" New topic
Author

coupling and cohesion

karthika gkumar
Greenhorn

Joined: Apr 15, 2008
Posts: 6
hi

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

Joined: Oct 13, 2005
Posts: 36453
    
  15
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

Joined: Nov 03, 2006
Posts: 1344
    
  12
Hi gk,

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

Best regards,
Katrina
karthika gkumar
Greenhorn

Joined: Apr 15, 2008
Posts: 6
i changed my display name
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: coupling and cohesion
 
Similar Threads
coupling and cohesion
coupling and cohesion in java
coupling cohesion in java
Cohesion and coupling
Can anyone explain what is coupling and cohesion with live examples and coding.