• 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 question

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Just a quick one about Coupling:

Would a class that contains objects of other classes be considered 'bad' or 'highly' coupled?

Eg.



I understand that these are coupled, but it won't matter if the internal representation of an Engine changes as long as the class remains of type Engine.

*Confused* :-)
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Would a class that contains objects of other classes be considered 'bad' or 'highly' coupled?



Coupling to some extent is necessary. In a meaningful application, an Object shouldn't be expected to do everything on its own.

Your example shows that the objects are coupled. The internal representation of the Engine can be changed as along as it doesn't effect the AirCraft or in any class where Engine objects are used.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
coupling should not be an issue, it is required a lot number of time. References of other class in a class is quite necessary. As Harish pointed out that one class can't do all the work therefore it needs to call other class to get the job done.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
I would regards that sort of coupling as “good”. It is a case of HAS-A; an Aeroplane HAS-AN Engine, HAS-[TWO] Wings, etc. Composition.
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can achieve loose coupling through "Dependency Injection".
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is why I like the Demeter Law. It reduces the coupling.

I wrote a post about it, if you are interested, here is the link: Demeter Law
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic