Tuesday, 8 March 2011

UML: A Class with Attributes and Methods 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 forthcoming blogs in the series, demonstrate the link between diagrams and code.



  /**
   * This is a class with a couple of attributes and methods
   */
 
public class A {
   
   
private String a1 = "Helo";
   
   
private String a2 = "World";
   
   
/**
     * An operation
     *
@return 0
     */
   
public int Op1() {
     
// Stuff goes here
     
return 0;
   
}
   
   
/**
     * Another Operation
     *
@return a new A
     */
   
public A Op2() {
     
return new A();
   
}
  }

No comments: