aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Compostion and abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Compostion and abstract class" Watch "Compostion and abstract class" New topic
Author

Compostion and abstract class

Sonal Ray
Ranch Hand

Joined: Mar 15, 2005
Posts: 56
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

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Sonal Ray
Ranch Hand

Joined: Mar 15, 2005
Posts: 56
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Compostion and abstract class