Topic
  • 1 reply
  • Latest Post - ‏2013-01-03T14:10:16Z by SystemAdmin
SystemAdmin
SystemAdmin
14225 Posts

Pinned topic Class implemeting interface in UML Model

‏2012-12-29T16:49:04Z |
I add interface to my UML Model Project in Rational Software Architect. And I made a class implementing it (class1 implements interface1) by choosing in class's Properties/Advanced/UML/Interface Realization - I added interface1 to this list. But when I add method1 to interface1 it doesn't appear in class1 automatically. Even when I add method1 to class1 manually it isn't identified with method1 from interface1. For example when I put a message to class1 in sequence diagram when it displays list of available operation (which can be this message) for class1 it shows interface1::method1 and class1::method1 like it was two different methods (and class1::method1 should be a realization of interface1::method1 !!!).

Can anyone help in this matter?
Updated on 2013-01-03T14:10:16Z at 2013-01-03T14:10:16Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    14225 Posts

    Re: Class implemeting interface in UML Model

    ‏2013-01-03T14:10:16Z  
    It seems to me that what you are seeing is working as designed.

    The behavior may be clearer if you actually try to generate code from the model.

    For example, suppose that you generate Java Code and you have a model with:

    Interface1::operation1
    Interface1::operation2

    Class1::operation1

    and Class1 realizes Interface1. When you run the UML to Java transform, you get this code:
    /**
    * <!-- begin-UML-doc -->
    * <!-- end-UML-doc -->
    * @author Lara
    * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
    */
    public interface Interface1 {
    /**
    * <!-- begin-UML-doc -->
    * <!-- end-UML-doc -->
    * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
    */
    public void Operation1();

    /**
    * <!-- begin-UML-doc -->
    * <!-- end-UML-doc -->
    * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
    */
    public void Operation2();
    }

    and

    /**
    * <!-- begin-UML-doc -->
    * <!-- end-UML-doc -->
    * @author Lara
    * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
    */
    public class Class1 implements Interface1 {
    /**
    * <!-- begin-UML-doc -->
    * <!-- end-UML-doc -->
    * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
    */
    public void Operation1() {
    // begin-user-code
    // TODO Auto-generated method stub

    // end-user-code
    }

    /**
    * (non-Javadoc)
    * @see Interface1#Operation2()
    * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
    */
    public void Operation2() {
    // begin-user-code
    // TODO Auto-generated method stub

    // end-user-code
    }
    }

    So the UML to Java transform does not need you to explicitely model the methods in the Class, it is enough that they are present in the Interface for the code to be properly generated. The same is true for the Sequence Diagram, where you can have a Lifeline associated to the class and you can select the method directly from the Interface that the Class realizes.

    Thank you and regards, Lara