Home
Username:
Password:
UML Tutorials

Advanced Class Diagrams / Templates




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

Next we're going to talk about templates. The object management groups UML specifications defines a template as follows, a template is a parameterized element that can be used to generate other model elements using template binding relationships. The template parameters for the template signature specify the formal parameters that will be substituted actual parameters or the default in a binding. And this movie is about putting that into plain English and giving some examples to show how templates work. Now if you're familiar with C Plus Plus you're probably familiar with parameterized classes. Classes that specify parameters that must be defined by any class that binds to them. In UML a parameterized class is called a template. A template lets you create a class that will work with other classes when you don't know specifically what those other classes are. So a template let's you provide abstractions for the type of class the template may interact with, much as an interface does with objects, but here we are talking about classes. To show a class as a template you use this symbol that you see here, classifier box with up in the upper right corner a rectangle with a dashed line outline. In the rectangle put a placeholder for the element type parameter. Here we're using T for type. When you use a template it's called a derivation and let's see how that works. So let's create another class and we'll call it binding class and to show that this class or instances of these class are derived from the template we use this style of arrow, straight line with a triangular arrowhead. Now when a particular instance of the template class is created you need to specify the actual type to substitute for the placeholder T. And this is called binding a type to the template and here's how you show it in your class diagram. You show a stereotype for your arrow here and use the bind stereotype. In addition as I've said you need to specify the actual type that's going to substitute for the placeholder in our example T. And you do that using this syntax, inside of angle brackets you put the template type and then you use a hyphen and another angle bracket to make an arrow and then the actual type. So it looks like that and this provides a specification of the actual type that will replace the placeholder. So let's look at an example of how this might work. Here we have a template called list and templates are very handy to use with lists, its one of the most common uses for templates and that list has its parameter up here and it has its features and down here book list is what we are binding to the template so you can see that we have the bind stereotype and we have the specification T is replaced with book and that shows how this derivation works. Now there is another way that can show this and this way is a little more compact. In the classifier you can write this syntax, list and then the angle brackets you used T and the arrow symbol, so it's the same specification that we saw over here but here is part of the classifier name and in this example you see that again this derives from the template list. Templates are fairly complicated but when you get the idea of how they work you'll find them very handy to use in your class diagrams, particularly if you're working with lists or maps of some kind.

Tutorial Information

Course: UML
Author: Nancy Conner
SKU: 33815
ISBN: 1-934743-23-2
Release Date: 2007-10-26
Duration: 7 hrs / 95 lessons
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available