• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

coupling and cohesion

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

what is coupling? what is cohesion?
i cant understand clearly those things in K&B book
please explain
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i changed my display name
thanks
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic