leeappdalecom wrote:
This is something like recursive generics lol

Your saying a container class that is the same type as the type it consumes?

I dont actually see a use for this apart from recursively creating a data structure that can consume itself.  Why would you need this?



I'll give you a clear 'simplified' example :

I have an aplication that is modulary built and pases entities (Class instances of type Entity) between modules in a loosely coupled fashion through a service.

Those entities are in the order of hundreds.

The thing is that over time for some entities there was the need to store snapshots them (an sorth of undo capability)

So the chosen path here was for those entities to implement the
"ISnapshot" interface. Wich meant subclassing and Implementing the interface or just implementing without sublasing

The thing is that the implementation is not dependent of the entities internal working. Is the same implementation over and over for every entity.

It has a StoreSnapshot method that basicaly clones the entity and store'it along with some other info.

So for this particular type of problem :
 - either write the same code (Copy Code) for every entity manualy - (VB6 Style)
- either use a for of automation like VB Scripts to implement the interfaces
- either use some sort of code generator

to do basicaly the same thing . Implement an Interface on a type tha't not dependent of the types's topology.

And the rezult was hundreds of identical implementations of the interface.

The other aproach would have been to create a Container Class to store the entities. But this could't be accomplished because :

- first of all a new service that passed container clases around had to be created to pas the new containe objects storing also the enties them selves and the snapshot data.

- The entities travel through diferent modules, some of wich are not interested in the snapshot capabilies of the entities so containers could'n be passed to them only entities. And it wasn't desired make those modules aware of the new type only for passing it arround.

- An module that dind't knew about the snapsot could't just recive an entity without container because he coul pass it to a module thar recognizes it and need it but that info would have been los.


I realy hope I managed to create a picture here ... Smiley

All this would have been infinitly more simple if

I could do this :

class Snapshot<T> :  T, ISnapshot where T : Entity {

}

and just modify my factory class to create Snapsot entities ould have solvel my problem in 5 mins not days , not to mention maintanace or the posibility of refactoring.