Wednesday, 9 March 2011

UML: Interface Realisation and Java

One problem you often see when dealing with UML is that some developers don’t get the idea that what you see in class diagram should translate directly into code they draw a class diagram and write some code and neither bare any resemblance to each other. This, and other blog forthcoming blogs in the series, demonstrate the link between diagrams and code.


  /**
   * This is our interface, it'll be realized, or implemented in Java speak, by MyTestClass
   */
 
public interface MyInterface {

   
/**
     * Method 1 specification
     *
     *
@param parameter
     *            The input arg
     *
@return Some String
     */
   
public String method1(String parameter);

   
/**
     * Method 2 specification
     *
     *
@param param2
     *            The input arg
     *
@return Some String
     */
   
public String method2(char param2);

 
}

 
/**
   * Class that implements -or realizes in UML speak - MyInterface
   */
 
public class MyTestClass implements MyInterface {

   
/** Some instance variable */
   
private String att1;

   
/**
     * Some operation that's not defined by the interface
     *
     *
@return 1;
     */
   
public int operation1() {
     
return 1;
   
}

   
/**
     *
@see uml.InterfaceReaisation.MyInterface#method1(java.lang.String)
     */
   
@Override
   
public String method1(String parameter) {
     
return null;
   
}

   
/**
     *
@see uml.InterfaceReaisation.MyInterface#method2(char)
     */
   
@Override
   
public String method2(char param2) {
     
return null;
   
}
  }

No comments: