• 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

Can a many-to-many relationship be a composition?

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following relationship:

Route * ------ * RouteLeg

I'd like to make this a composition since a Route is composed by multiple RoteLegs. However, if I delete a Route, its RouteLegs do not necessarily get deleted too, since they may be used to compose other Routes. Is it still appropriate to show this relationship as a composition?

Like this: Route * <>---- * RouteLeg

Thanks very much in advance.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Henrique Ordine:
Is it still appropriate to show this relationship as a composition?



Not really. With composition there is the expectation that the whole is responsible for the life-cycle management of the part - particularly the end of the lifecycle. In other words, there is the assumption that the "part" will cease to exist if the "whole" is destroyed.

So you are stuck with aggregation.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And to expand on what Peer said, there always needs to be exactly *one* "whole" that is responsible for the "part". Which one it is might change during the lifetime of the "part", but it's always a one-to-one or one-to-many relationship, never many-to-many, by definition.
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, thanks very much guys for your answers. I thought I'd never understand the difference between aggregation and composition.
 
reply
    Bookmark Topic Watch Topic
  • New Topic