aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes A sample of template class code realization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "A sample of template class code realization" Watch "A sample of template class code realization" New topic
Author

A sample of template class code realization

Sergei Zhylinski
Ranch Hand

Joined: Nov 15, 2013
Posts: 64
    
    1
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.


[Thumbnail for UML_class_diagram_template.png]

Tim Cooke
Bartender

Joined: Mar 28, 2008
Posts: 1173
    
  65

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.

Tim Driven Development
Sergei Zhylinski
Ranch Hand

Joined: Nov 15, 2013
Posts: 64
    
    1
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

Joined: Feb 26, 2001
Posts: 5018
    
    8

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: A sample of template class code realization