Virtualized (non-generic) Net list class. C++


Log Messages and Errors

Mouse Events

State
State
Test Console

Test Data

C++ virtualized (unsealed) generic list


Having heard many complaints regarding the number of .Net classes that were sealed I had an academic interest in the issue. I remain focused on using generics to resolve this sort of problem and would for instance, adapt this code to be generic instead. Regardless, given compiler optimization, what sort of performance cost would result from unsealing any given class using virtual methods, shadowing and base method calls.


Though there nothing particularly remarkable about it, I unsealed Generic List by:
1. I created a base class that instantiates List.
2. Created a virtual member for each member of List.
3. Within each member, perform base.member(...).
4. Extended List with what little additional functionality could be needed.

Note I did not implement .Net's IList.

The specific part of the standard that resulted from this work was to:
1. Use both composition within C++ multiple inheritance and inclusion in order to create robust objects.
2. Use C# where single inheritance was adequate.
3. Part of the objective was to finalize implementation details and determine the deficits of a pre-processor in VS.
4. There is of course a performance cost involved. The generics solution above is excellent without the performance costs. It was not chosen because the objective of the research was specific to sealed classes.
5. The task was not justifiable because of any missing features in List except for a forward / back ability for enumeration and collections. Where this would be useful is for adding low level features present in a larger framework or to simply inherit this class.

Anyone wanting a copy of the source to save time can contact me at david_horsman AtSymbol hotmail.com.


Regards,
Dave Horsman



Discussion of project relevance

So in basic terms this is a version of the List class that is not sealed. It of course could be used as a base class for extending the functioinality of List.

The List class doesn't have a strong need to be unsealed from my point of view. It was good choice in that it was not a lot of work. Aside from the increased dereferencing that would seem to occur it doesn't seem too difficult a work around.

The intent to expose the class for enhancement is hopefully clear but to date I have only a few methods that might be used regularly. I would also be interested in a bench test against a generic version of list to determine the relative performance of the two strategies.

Jeffery A. Becker's
Generic
List

Jeffery A. Becker provides an excellent solution that uses generics to unseal generic list.

This can be found on line at the ASP forum:

http://forums.asp.net

at the following link:

http://forums.asp.net/p/1345001/4027690.aspx#4027690

I have included Jeffery's code at the above link in case anyone has arrived at this page looking for a well implemented use of generics rather than sealed classes. I would recommend Jeffery's solution over the study class produced in this project baring the unilikely event that performance was similar.

Anyway, Jeffery's code shows what I believe is the correct approach to the sealed classes problem in most cases. That is, extension through the use of generics. If nothing else, it certainly demonstrates the purpose and proper use of generics.

Keywords and Related Topics

As part of a larger academic project I created this a non-sealed ?virtualized? generic list class.

Without worrying too much about which language is involved, the related topics (tags, key words) for this area are :
" shadowing
" override, new and virtual
" name Ambiguities
" anonymous types
" scope (block, procedural etc), inheritance.
" classes, partial, sealed
" virtual vs non-virtual base classes
" wrappers, composition and aggregation

The Project

This was a very basic project that provides an example of some of the test and evaluations done during the C# evaluation. This one was grouped with tests on weak object usage. Using pools of objects. Creating base classes to replace partial classes in Silverlight. Interop evalation. DLR evaluation, etc.

Most of these types of evaluations are done within the normal process of development on one project or another. Clearly the unsealing task was somewhat stand alone. It is part of larger decision process of selection between generics and extended classes.