Home > .NET Framework > CLR Generics – Terminology

CLR Generics – Terminology

A running example – Pseudo code of the List (List of Tee) class in the System.Collections.Generic namespace of BCL.

[serializable]
public class List :  IList, ICollection, IEnumerable, 
	IList, ICollection, IEnumerable {

	public void Add(T item);
	public T[] ToArray();
	// ... rest of the code elided for clarity
}

// A Client of List
public class Program {
	public static void Main(string[] args) {
		List list = new List();
		list.Add(1);
	}

Terms
Generic Type:
A generic type is a type which has one or more parameters (called type parameters). In the example List is a Generic type because it has one parameter (called type parameter) T.

Generic Type Parameter:
A generic type parameter is a place holder type used by generic types. In the List example above T is the placeholder type. Hence T is the generic type parameter.

Arity:
Arity is the number of type parameters a generic type has. In the List example above the arity of the List type is 1, since T is the one and only type parameter.

public class DictionaryEntry ...

The arity of DictionaryEntry is 2 since it has two type parameters.

Generic Type Argument:
A generic type argument is the type provided by the client while declaration / instantion. In the above example int is the generic type argument.

Constructed Type:
A constructed type is a usage (declaration) of the generic type in which the client has specified at least on of the type parameters as a type argument. A type argument need not be a concrete (non generic / generic type to which all the type parameters are specified – do not confuse this with abstract / concrete used to describe inheritance relationships) type like int as in this example. It can also be a type parameter. We’ll see an example of this in the definition of a open constructed type

Closed Constructed Type:
A closed constructed type is one to which all the type parameters are specified as type arguments using concrete types. In the above example, List is a closed constructed type because it has its only type parameter T specified as a type argument int.

Open Constructed Type:
A Open constructed type is one to which atleast one of the type parameters is specified in terms of another type parameter. This is slightly confusing. Let us see another example here.

public class DictionaryEntry ...

// An dictionary entry which has integer keys
public class IntegerKeyBasedDictionayEntry {
	private inetegerKeyBasedEntry DictionaryEntry;
	...
}

Here only one of the two type parameters specified is concrete, int. The other is specified in terms of the type parameter TValue itself. This is a open constructed type.

Whew so many new terms, well it is needed if you need to understand any article written on generics.

Advertisements
Categories: .NET Framework
  1. No comments yet.
  1. November 19, 2010 at 10:59 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: