Does the Stereotype have to be a 'T'?

Now that .NET developers have access to Generics in both VB.NET and C#, questions are being asked about an approach often used by C++ developers called Templates.  When we define a Generic class we must follow the class definition with a Stereotype (also referred to as a Parameter Type).

Such as (VB.NET):

Public Class MyStackTvb(Of T)

Private frames As T()

Private pointer As Integer = 0

Public Sub New(ByVal size As Integer)

frames = New T(size) {}

End Sub

Public Sub Push( ByVal frame As T)

frames(pointer) = frame

pointer += 1

End Sub

Public Function Pop() As T

pointer -= 1

Return frames(pointer)

End Function

End Class

or in C#:

public class MyStackTcs< T >

{

private T[] frames;

private int pointer = 0;

public MyStackTcs( int size )

{frames = new T[ size ];}

public void Push( T frame )

{frames[ pointer++ ] = frame;}

public T Pop()

{return frames[--pointer];}

}

We are not required to use the name 'T' for the template parameter.  You could use 'Z' for all anyone might care.  But trust me, programmers will care to follow a standard that has been in use for over a decade.  Think of 'T' as 'Type' if this helps.

Until next time........

Published Tue, Apr 12 2005 23:13 by Keith Nicholson
Filed under:

Comments

# re: Does the Stereotype have to be a 'T'?

Saturday, April 16, 2005 11:04 PM by Keith Nicholson
I have posted some sample code out there at http://share.ksdynamics.com/BlogCode/Sample%20Docs/GenericStereoType.zip

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Powered by Community Server (Commercial Edition), by Telligent Systems