Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UML diagram of a Java Servlet API

 
Sergei Zhylinski
Ranch Hand
Posts: 84
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I've found a brief UML class diagram for a Java Servlet API. And I wonder wether this diagram is correct. Specifically I would like to clarify association relationships.

Firstly, the know and unknown classes in an association. For instance, look at the association between classes "ServletOutputStream" and interface "ServletResponse". It is uni-directional association. According to this article, a "uni-directional association is drawn as a solid line with an open arrowhead (not the closed arrowhead, or triangle, used to indicate inheritance) pointing to the known class". Therefore, the known type in our case is "ServletOutputStream". Lots of books (particularly, UML Distilled by Martin Fauler) say that association relationships are realized as fields in source code. And thats why, following the logic, class "ServletOutputStream" should contain the reference to a "ServletResponse" instance. But, on the contrary, "ServletResponse" has a getter for a "ServletOutputStream" (getOutputStream()).
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Sergey!

Indeed, I too think this diagram is wrong. In the case of the ServletOutputStream -> ServletResponse relationship, I think I'd go with the dashed arrow from ServletResponse to ServletOutputStream, so it would be ServletResponse ------> ServletOutputStream. Although an interface cannot hold state, it would mean that the concrete classes that implement ServletResponse would depend on ServletOutputStream (well, in this case, the interface itself also depends on ServletOutputStream, because a method in it returns ServletOutputStream). And the relationship would be represented by the dashed arrow because this means dependency, which is used in cases where a class depends on another, for instance, when a method on class A returns class B, or class A receives class B as parameter on a method, etc.

There are other mistakes, like the relationships between ServletConfig, ServletContext and RequestDispatcher. It's the other way around, and I think I'd go with dashed arrows too.
 
Sergei Zhylinski
Ranch Hand
Posts: 84
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I would choose aggregation from interface "Servlet" to interface "ServletConfig". I've opened the source code of the servlet api:



Am I right?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct!
 
Sergei Zhylinski
Ranch Hand
Posts: 84
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto Perillo wrote:Correct!


I've recently accomplished my own UML class diagram. Could please look at it?

Servlet_API_class_diagram.png
[Thumbnail for Servlet_API_class_diagram.png]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic