simple UML question

I have a LayerManager which can have from 1 to many Layer objects. Each Layer object has a GraphicsBuffer object which is a subclass of the java.awt.image.BufferedImage object.

I've made two diagrams and I would like you to tell me which one do you think is correct.

the link is : http://users.otenet.gr/~herouvim/ioannisc/uml.png (7 kb)

should I include both composition and generalization in the same diagram ?

thanks

[452 byte] By [ioannisca] at [2007-9-28 5:58:48]
# 1

A looks more correct.

And yes you can have generalization and composition in the same diagram - they are unrelated concepts. In fact, you can have association, composition, aggregation, realization, and dependancies all in the same diagram.

Keep in mind that composition means the composite instance has it's lifecycle controlled by it's owner and that no other instance (of anything) references it directly.

larsonaa at 2007-7-9 17:09:50 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

> A looks more correct.

>

> And yes you can have generalization and composition in

> the same diagram - they are unrelated concepts. In

> fact, you can have association, composition,

> aggregation, realization, and dependancies all in the

> same diagram.

>

> Keep in mind that composition means the composite

> instance has it's lifecycle controlled by it's owner

> and that no other instance (of anything) references it

> directly.

hi larsona...

i'm in the process of learning UML... and i do agree that A is more correct.

But let's say BufferedImage has two or more subclasses ie. SomeBuffer and GraphicsBuffer. Then, would B diagram be applicable? Is this kind of design considered good or worst? ie. it would provide whatever Buffer objects to the Layer object, but perhaps it can generate runtime error that connect be traced during compiling..

I hope you can shed a light....

muhdkamila at 2007-7-9 17:09:50 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

Both diagrams appear to be correct but don't represent the same situation - one shows that LayerManager contains GraphicsBuffer instances (which extend BufferedImage) whereas two shows that LayerManager contains BufferedImages (of which GraphicsBuffer is a subclass).

"Good" design would probably dictate that you should reference the most general class possible. So if LayerManager could contain a collection of BufferedImage instances (which may happen to be instatiated as GraphicsBuffers) then you should use that approach, in which case diagram 2 would be correct. A note could then be used to connect LayerManager with its dedicated/optimised BufferedImage subclass to explain its relevance on the diagram.

For the multiple subclass situation it may be considered "better" design to create a GraphicsBuffer interface which may then be implemented by various BufferedImage (or other) subclasses.

Hope this helps.

KPSeala at 2007-7-9 17:09:50 > top of Java-index,Other Topics,Patterns & OO Design...
# 4

Hi,

As other guys discuss in the forum that yes you can have association, compostion, aggregration in one UML diagram.

if you depicting a composition relation between two object like in your 1 case between LayerManager and Layer make sure that you will Layer will destroy once you destroy the instance of LayerManger. No other object will reference it instance directly.

I will prefer to have your B diagram, the reason is very simple that if some later point of time you have more subclasses of your BufferedImage class.

-Abhay

abhay_mehrotraa at 2007-7-9 17:09:50 > top of Java-index,Other Topics,Patterns & OO Design...