1

I have the following code snippet:

contract Bar{

}
contract Foo { 
     Bar bar = new Bar(); 

}

When I am generating the class diagram from sol2uml I get the following diagram:

Class Diagram

I want to have a composition relation between Foo and Bar class. enter image description here

I am not sure if this code is correct for this relationship or there is some problem with sol2uml.

Maliha
  • 45
  • 1
  • 5

2 Answers2

0

yeah, what you do is a composition relationship. Composition is a "has-a" relationship. The lifetime of the Bar is dependent on the lifetime of the whole Foo.

As t2informatik says:

A composition is visualized with a line between the model elements and a filled diamond on the side of the whole.

So it looks like tool generated incorrect diagram.

StepUp
  • 36,391
  • 15
  • 88
  • 148
  • Shouldn't the symbol between Foo and Bar be a diamond sign rather an arrow? – Maliha Oct 20 '22 at 11:32
  • @Maliha yeah, you are right, composition should be shown as **filled diamond**. Please, see my updated answer. Thanks! :) – StepUp Oct 20 '22 at 12:24
0

It is not a has-a relationship. Basically, it is an association type between Bar and Foo. For instance, if you have a relationship A --> (local) B (plantuml), then you have the following code (Java).

public class A {
     public void f() { //local behavior
         B b = new B();
     }
}

When you have a composition, you need to think like when you delete the Bar, a n abstract type of the Foo class cannot

zoint
  • 108
  • 2
  • 15