In fact, I am working on an atm site where generics make my work a lot easier. I need to access a lot of information from the database, since the whole site is managed by the database, so I really wanted to have one class to implement the database functionality. This class inherits more classes that know how to deal with their respective data.
For example, I have a Products class that deals with Products data and a Themes class that deals with topics, etc. Well, all of these classes need a common format for reading and writing. So, I created a recording class that handles this.
Now, where does the Generics game begin. I created the Product class, Theme class, etc.,. with strongly typed members like Name, Manufacturer, ThemeId, however the Records class has no idea how to deal with them. Thus, the database class is of a type related to a particular class, Product, Theme, etc.,. and the recording class also uses the Generic type, so I can write code like ...
Product.Name = "Cool Product";
then save it as ...
Products.InsertRecord(Product coolProduct);
Not only does it save a lot of input, but it allows me to have one class that handles all the dirty work, while these little stub classes provide me with a readable, strongly typed interface.
In any case, sorry for the long branch. Hope this helps you understand the power of generics, at least in this case.
rpiontek
source share