I created two simple classes A and B in Visual Paradigm software, such that there there a COMPOSITION between these two classes. However, the generated code (in Java) is the same with OR without the association between these two classes. In other words, the generated code, if there is a composition between class A and B, is the same as when I deleted the composition between class A and class B. That is, the composition between classes is NOT considered in generated code by Visual Paradigm. What is the solution?
Edit: Based on the request of @Christophe, I added the photo of a test example project (class diagram), along with two Java class generated by Visual Paradigm, where in both cases (with and without composition relation between two classes) the generated codes are exactly the same.
Generated codes by Visual Paradigm:
public class Class {
private int attribute;
public void operation() {
// TODO - implement Class.operation
throw new UnsupportedOperationException();
}
}
public class Class2 {
private int attribute;
public void operation() {
// TODO - implement Class2.operation
throw new UnsupportedOperationException();
}
}
P.S. I tried it with IBM Rational Rhapsody and it works much better. That is, it generates in the code the features of the model in more detail. See the generated code below by IBM Rational Rhapsody and compare the differences with the code generated by Visual Paradigm:
Generated code by IBM Rational Rhapsody:
package Default;
//----------------------------------------------------------------------------
// Default/class_0.java
//----------------------------------------------------------------------------
//## package Default
//## class class_0
public class class_0 {
protected int attribute_0; //## attribute attribute_0
protected class_1 itsClass_1; //## link itsClass_1
// Constructors
//## auto_generated
public class_0() {
initRelations();
}
//## operation Operation_1()
public void Operation_1() {
//#[ operation Operation_1()
//#]
}
//## auto_generated
public int getAttribute_0() {
return attribute_0;
}
//## auto_generated
public void setAttribute_0(int p_attribute_0) {
attribute_0 = p_attribute_0;
}
//## auto_generated
public class_1 getItsClass_1() {
return itsClass_1;
}
//## auto_generated
public void __setItsClass_1(class_1 p_class_1) {
itsClass_1 = p_class_1;
}
//## auto_generated
public void _setItsClass_1(class_1 p_class_1) {
if(itsClass_1 != null)
{
itsClass_1.__setItsClass_0(null);
}
__setItsClass_1(p_class_1);
}
//## auto_generated
public class_1 newItsClass_1() {
itsClass_1 = new class_1();
itsClass_1._setItsClass_0(this);
return itsClass_1;
}
//## auto_generated
public void deleteItsClass_1() {
itsClass_1.__setItsClass_0(null);
itsClass_1=null;
}
//## auto_generated
protected void initRelations() {
itsClass_1 = newItsClass_1();
}
}
/*********************************************************************
File Path : DefaultComponent/DefaultConfig/Default/class_0.java
*********************************************************************/
Second class code:
package Default;
//----------------------------------------------------------------------------
// Default/class_1.java
//----------------------------------------------------------------------------
//## package Default
//## class class_1
public class class_1 {
protected int attribute_0; //## attribute attribute_0
protected class_0 itsClass_0; //## link itsClass_0
// Constructors
//## auto_generated
public class_1() {
}
//## operation Operation_1()
public void Operation_1() {
//#[ operation Operation_1()
//#]
}
//## auto_generated
public int getAttribute_0() {
return attribute_0;
}
//## auto_generated
public void setAttribute_0(int p_attribute_0) {
attribute_0 = p_attribute_0;
}
//## auto_generated
public class_0 getItsClass_0() {
return itsClass_0;
}
//## auto_generated
public void __setItsClass_0(class_0 p_class_0) {
itsClass_0 = p_class_0;
}
//## auto_generated
public void _setItsClass_0(class_0 p_class_0) {
if(itsClass_0 != null)
{
itsClass_0.__setItsClass_1(null);
}
__setItsClass_0(p_class_0);
}
//## auto_generated
public void setItsClass_0(class_0 p_class_0) {
if(p_class_0 != null)
{
p_class_0._setItsClass_1(this);
}
_setItsClass_0(p_class_0);
}
//## auto_generated
public void _clearItsClass_0() {
itsClass_0 = null;
}
}
/*********************************************************************
File Path : DefaultComponent/DefaultConfig/Default/class_1.java
*********************************************************************/
As you can see, the codes generated by IBM includes the associations (compositions) and other features as well.
Here is the class diagram of above codes generated by IBM Rational Rhapsody: