Tuesday, 31 May 2011

UML, the Template Class 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 blog demonstrates how to draw a template class in UML followed by its equivalent Java code and looking at it you'll notice that the Java code is all about generics. I guess that's because UML's template class idea stems from C++'s template classes, which are similar to, but not a direct equivalent of Java's generics.

  public class MyList<T> {
   
   
public String method1(T arg0) {
     
// Add some real implementation here!
     
return "Hello world";
   
}
  }

No comments: