Well, here's an example from something I am doing-
1. Users define their own object by extending a prototype object. Users may customize any portion of their object while the prototype still handles all ambiguous operations. This is done by creating stub methods that handle specific operations for the handle. The only problem is how does the prototype manipulate the handle without knowing what it is, and how do you keep this handle within the interface?
-Private variable of the handle cannot be used as it cannot be accessed via the interface. Defining a variable in the interface requires that it have a specific type, thus the private variable could not be declared within the interface meaning that it cannot be accessed by it. Because of the ambiguity of the system (you never know what types of objects you are handling), you must access objects initially from the interface within the prototype.
-Using a hashtable would be messy and complicated as you would be required to pass either the entire hashtable each time or an integer referencing an index in the hashtable, which requires yet more variables and more complexity and makes everyone's life hard.
-Using a set of structs allows the struct instance to be used without knowing what it is. The integer can also be passed from method to method and accessed quite easily.
-In my specific thing, only certain handles can be used. These are handles with
an X and Y coordinate
an owning player
a type id
However, this can be expanded into a broad range of categories as handles can be given an artificial owner, artificial x and y coordinates, and even an artificial type id. This is due to the fact that the user of the system has control over getting the properties of the handle, meaning they can return whatever they like. The x and y coordinates are used for where the effects of the handle are to take place, the type id is used to create the handle's type (not needed), and the owning player is to create objects attached to the handle for a specific player (once again can be artificially done)
So how could this be useful? In cases where the thing that is being designed is extremely ambiguous
What does it have to do with typecasting? It allows users of those ambiguous designs to typecast data (it takes Unit u, but you cast it to an Item object) so that they may more easily use the construct while maintaining speed.
A very simple library of structs named after handles
^_^