• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

query

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are Has-a relationships always tightly coupled ? why or why not.
 
Ranch Hand
Posts: 72
Scala Monad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hope i interpret your problem correctly,

has-a relationships are not always tightly coupled.

Ex:

1) Car has an engine //tightly coupled, since a car cannot exist without an engine.

2) Department has employees //loosely coupled
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer is no, but Marimuthu's example isn't right.

You can create a has-a relationship by using composition (which is the normal way to represent a has-a relationship in an object oriented program). But the member variable can be of an interface type; that way, the containing class isn't tightly coupled to the implementation of the contained class.
 
Marimuthu Madasamy
Ranch Hand
Posts: 72
Scala Monad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what Jesper said is correct.
But i interpreted it in this way.

Has-a relationships can be implemented by using both Composition and Aggregation. Here the difference is that in Composition, the lifetime of the contained object is controlled by the class which contains it.
That means in my example,

If i delete a car object, the engine object should also be deleted. (the engine alone cannot alone live without a car) (Another example, Human & heart). This is composition (Strong relationship).

But if i remove a department, employees can still live without that department. (Aggregation) (Another Example - Computer & Printer)

From Jesper's statements ("coupled to the implementation of the contained class"), I think aggregation and composition are not related to coupling.
 
It's a tiny ad only because the water is so cold.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic