Model Xtractor - Online Class Diagram Editor
Model Xtractor - Online Class Diagram Editor User Account   
    RSS Posts | Model Xtractor
  • Diagrams
  • Metadata
  • Blog
  • Support
  • Tutorial

Generics

Leave a Comment » Feb 22, 2010
Bookmark and Share
Categories: Tutorial

Model Xtractor can represent efficiently not only template definitions, but also template substitutions, which are virtual generic types, similar to template constructs, “derived” from the same template definition, but using different generic parameter names or types. Each template substitution is “linked” to its template definition shape through the special auto-expanded <<template>> dependency item. For each generic parameter that can be represented by a shape, Model Xtractor also generates a <<param>> dependency item.

Template Definitions and Substitutions

While most languages today (C++, Java, C#) use the <..> notation for generics or templates, we’ve seen no need to adopt the different shape representation required by UML. A Dictionary<TKey, TValue> generic class will have the same title in Model Xtractor as in C#, C++ etc.

Click for the published entry of the diagram
EditViewPrint

Dictionary<TKey,TValue> implements IDictionary<TKey,TValue>, which inherits from ICollection<KeyValuePair<TKey,TValue>>. This .NET dictionary is in fact a collection of KeyValuePair objects. There is no template definition with such parameters for the last interface. The actual definition is only for ICollection<T>, where the generic T parameter has been substituted with KeyValuePair<TKey,TValue>. ICollection<KeyValuePair<TKey,TValue>> will contain two template-related dependency items, automatically added by Model Xtractor and expanded in the diagram:

  1. <<template>> –> ICollection<T>, which defines our interface as a template substitution (similar to an open construct in C#/.NET) of a well-defined generic type. The expanded item connector looks like the generalization connector, but the big triangle is filled-in with black.
  2. <<param>> –> KeyValuePair<TKey,TValue>, which is a parameter substitution. The expanded item connector looks like the dependency connector, but with a big arrow.

The diagram contains other template and param expanded items, easily identified now as such. All highlighted shapes are template substitutions.

Template Parameter Substitutions

Model Xtractor internally and dynamically creates a template substitution type each time a parameter list is different from the original template definition. It is enough to see a different generic parameter name, even if the whole signature is actually the same. Main difference from a C# template construct is the compile actually generates a new class each time it’s based on a template.

Model Xtractor automatically creates a parameter substitution for any combined generic parameter from which we can further navigate to a type-based shape. This was the case for KeyValuePair<TKey,TValue> in the previous diagram, but not for any template below. T, TKey or TValue alone are just simple names, from which we cannot generate shapes.

Click for the published entry of the diagram
EditViewPrint

Both ValueCollection and KeyCollection, nested types of Dictionary<TKey,TValue>, implement essentially the same generic ICollection<T> interface. However, Model Xtractor has to generate two different template substitutions (highlighted shapes), because one is a collection of TKey, the other of TValue. T, TValue or TKey are just symbolic names, but we need to see them as such in the diagram.

Leave a Comment

Accepts [code lang=".."] .. [/code], where lang is one of: csharp/vbnet/java/js/c/cpp/xml/sql/as3/php/ruby

E d i t   D i a g r a m s   O n l i n e !
Advertisement
Last Recommended Diagrams
  • WCF Binding
  • Membership (System.Web.Security Namespace)
  • System.ServiceModel.Syndication Namespace
  • System.Configuration: Sections and Groups
  • System.Configuration: Specific Sections
  • mx.utils
  • mx.preloaders
  • mx.controls.menuClasses
  • mx.controls.listClasses
  • mx.controls.dataGridClasses
Last Recommended Diagram
WCF Binding
WCF Binding
© 2010 Model-Xtractor.com - All Rights Reserved.
  • Terms of Use
  • Privacy Policy
  • News
  • About Us
  • Contact Us