File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A sample of template class code realization

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

Could someone provide a source code in Java for the class diagram attached below? This class diagram was borrowed from the book "UML Distilled" by Martin Fauler, p. 82. The book itself does not provide any source code for an entire diagram, only for a template class.
UML_class_diagram_template.png
[Thumbnail for UML_class_diagram_template.png]
 
Tim Cooke
Sheriff
Pie
Posts: 2706
110
Clojure IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergey Zhylinsky wrote:... Martin Fauler ...

I'm not sure Martin Fowler will thank you for that.

Unfortunately you are unlikely to find anyone here who will just hand over the code for you (NotACodeMill <-- click). However, if you make an attempt at implementing this pattern yourself and come back with any specific problems you encounter then I'm sure you will be very successful with finding some help.
 
Sergei Zhylinski
Ranch Hand
Posts: 84
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. I do have some assumptions. In our case, "EmployeeSet" is not marked as a template subclass, therefore "Employee" is a type but not a type parameter. The code is as follows:



If you suggest copyright infringement, I will edit my message.
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergey Zhylinsky wrote:If you suggest copyright infringement, I will edit my message.

I think Tim was only suggesting that Martin would appreciate getting the spelling of his name right. It's "Fowler", not "Fauler" as you wrote in your original post.

The Java Collections library already has interface Set genericized, so you don't need to define a class Set<T> like that. All you have to do is declare something like this:

I see no reason to define an EmployeeSet class just so you can conform to the diagram down to each little detail.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic