• 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

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any difference between the terms loose coupling and weak coupling?
yup
- Raj
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From a quick Google search, they appear to be synonymous. And the terms are used interestingly in many fields besides programming!
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, there is no difference (other than in spelling ).
 
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Originally posted by Ilja Preuss:
No, there is no difference (other than in spelling ).


But I like the term weak coupling due to the word strong coupling
Bye,
Viki.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting. I guess I always used high and low. "High cohesion, low coupling!" Must have learned that in the 70s. Can't keep up with you kids with the long hair, the rock & roll, the strong & weak coupling.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the more commonly used adjectives for coupling are "tight" and "loose"
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tight coupling is when you use the class name to reference to an object rather than it's type(interface). for example explicitly naming vector in method signature is tight coupling. a better way is to use collection in the signature and cast the collection. that is loose coupling. this is so that you can change the underlying implemetation of the method without changing the actual interface(method signature) if you wanted to use an arraylist.
well that is what i was told when i was a junior.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Raid:
tight coupling is when you use the class name to reference to an object rather than it's type(interface). for example explicitly naming vector in method signature is tight coupling. a better way is to use collection in the signature and cast the collection. that is loose coupling. this is so that you can change the underlying implemetation of the method without changing the actual interface(method signature) if you wanted to use an arraylist.


You are right that one way to reduce coupling in a system is to refer to (that is, depend on) interfaces instead of actual implementations. Is is not a *definition* of the terms tight/loose coupling I would be aware of, though.
 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but surely there must be a difference Ilja between tight and loose coupling? i believe a system can be described as loosely coupled if you can muck about with the underlying code but the api still remains unchanged. using types and not explicit refernces. i would consider an application that uses interfaces to be loose coupled. this makes it less dependant on actual concrete classes and therefore less "joined".
i remember being asked a question regarding coupling in an interview. gave that answer. i never got the job. ha ha. take from that what you will.
but there is no differnce that i can think of between weak and loose. differnt words same meaning.
[ June 28, 2003: Message edited by: David Raid ]
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Raid:
i believe a system can be described as loosely coupled if you can muck about with the underlying code but the api still remains unchanged.


I would rather say that a system is loosely coupled when you can apply a change to a part of it without affecting many other parts.

i would consider an application that uses interfaces to be loose coupled. this makes it less dependant on actual concrete classes and therefore less "joined".


That's one part of coupling, but not the only one.
One other thing to consider is the "multiplicity" of coupling. A class depending on a big amount of other classes/interfaces is more coupled than one depending on just a few ones.
Another one is the matureness of the existing abstractions. A view (say, JSP) directly making JDBC calls is much stronger coupled to the database than a view getting his data from a business model layer. Or think of a List interface containing a getArray() method and clients depending on changes to the array being reflected by the list. In this case, the interface wouldn't buy you much - implementing a LinkedList to this interface would be near to impossible.
You can even have coupling between classes which don't know each other directly. Think about a method getting an array of Objects from class A and passing it to class B, which expects all the Objects to be Strings. Now you can break the functionality of B by letting A put an Integer into the array.
All those dependencies (and certainly others, too) are a form of coupling.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another aspect of coupling is coupled (!) to the age old concept of information hiding. If a class exposes its implementation details, it is easier for other classes to become inappropriately coupled by using that knowledge. If a class hides its details behind a simple set of public methods (or interface) it is harder for other classes to become inappropriately coupled.
Ever see an expression like getFrame().getPanel().getWidget().getText()? That code couples itself to the structure of the frame, the panel and the widget. Yikes! An interface with something like getCustomerName() is much harder to go wrong with.
Another measure I use for coupling, somewhat tongue in cheek but mostly seriously, is the complexity of the instructions to use something. If the directions say put three XML files in certain directories, call three methods in sequence, wave a dead chicken over the code, call two more methods, do some intricate transformation of the data and call another method, I'm outta there.
That's just another way of saying what Ilja put well: "a system is loosely coupled when you can apply a change to a part of it without affecting many other parts."
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic