This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compostion and abstract class

 
Sonal Ray
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , I have a small doubt in UML -- can an abastract contain Composition realtionship with other class?

I have 5 classes with following relationship:

1. Traveller --------------- Vehicle
(uses)


2. Vehicle---------------------Wheel
Composition


Now Vehicle is an abstract class and it is extended by Bus and Taxi.




3. Vehicle -------------(extends) BUS
^
|
|
|
TAXI


I am not getting the significance. I can not directly instantiate Vehicle class as it is abstract. And composition relationship with Wheel means, Wheel will be deleted when Vehicle is deleted. So , my question is can we have compostion relation with an abstract class? Would plz clarify
[ April 01, 2006: Message edited by: Sonal Ray ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sonal Ray:
I am not getting the significance.


It just means that both Bus and Taxi have a composition relationship to Wheel.

And composition relationship with Wheel means, Wheel will be deleted when Vehicle is deleted.


Not exactly. Composition means that the "whole" has lifetime responsibility for the "part", *but* that responsibility can be passed around. That is, before being destroyed, a Vehicle instance can decide to pass its wheel instance to a different Vehicle, which takes over lifetime responsibility.
 
Sonal Ray
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:


Not exactly. Composition means that the "whole" has lifetime responsibility for the "part", *but* that responsibility can be passed around. That is, before being destroyed, a Vehicle instance can decide to pass its wheel instance to a different Vehicle, which takes over lifetime responsibility.


Thanks a lot. It clarifies my doubt.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic