Today I want to introduce you some classes design that I think it might tend to be worthsome to be used in any database oriented application development. The classes design involves a list-like structure and a data structure element class. They are OBList<T> for the list class design and OBItem<T> for the data structure class design.
Most of us may had familiarized with any database query keywords that used to query a specific record which met the criteria of a specified search constraint. The most favorably query keyword maybe the " LIKE " statement that had invariably used in almost any database operation. For example: " LastName LIKE ' %Wu% ' ". The design made to these classes are so simple that to the any extend it even allow a LinQ statement query over its instance.
The class OBList<T> is derived from the System.Collections.Generic.List< OBItem<T> >. The OBItem<T> which is a data element to the list adopts a key->value pair like structure to its class design. The class OBList<T> will encapsulate the OBItem<T> data element class. It is to say that an OBItem<T> object is a data element to the OBList<T> instance. From those designs workout, because OBList<T> is derived from the standard System.Collections.Generic.List<T> class, we can then cozy up with the using of any standard functionality derived in the OBList<T> for any sort of managements that may incurred to the number of OBItem<T> elements in the list. The System.Collections.Generic.List of the .NET Standard class had a bunches of mostly useful methods and properties for any sort of data managements that may incurred to its elements in the list. Such a standard method even imply an anonymous delegate to its sort procedure so we can get more easy and felt lightness in the coding job itself. Other fascinating facility of the standard class involves a this member property of the class which can enumerate to any data element in the list as long as the key index used is any derivation of the .NET Object class. Any extending capability of the .NET standard List<T> class includes an ability to receipt a LinQ query statement used to query data over the structure of its instance.
The use of OBList<T> in the program design is quite simple and not complicated. You should first defined any data element of OBItem<T> that you want to add to the list of OBList<T>. We then use looping to iterate through number of OBItem<T> elements in the list for the add, delete and modify of OBItem<T> object in the list. The standard List<T> class provides the " Add " method for adding any new item object to its internal storage. The "Add" operation is so simple that you only need to provide the data " value " part as argument to the method, the key part is automatically calculated for you. Soon you'll see how can this be performed and be possible throughout the coding.
In compare to the standard .NET key->value pair Dictionary or HashTable class to either of which we should specify completely the key and value part of the data element be added like the following illustration describes about.
- HashTable hst = new HashTable();
- hst.Add(<Key>,<Value>);
Instead of that, consider my OBList<T> special characteristic such as,
- OBList<string> obst = new OBList<string>();
- obst.AddItem("some value data");
- Console.WriteLine("Key value is : {0}, Data value is : {1}",obst[0].OBKey,obst[0].OBContent);
Beside it is a good example of holding an array of sets, it even can turn itself to support multifaceted of data needed in the program. Supposes we want to add number of items from a ComboBox to the list, then this can become more easier than the usual standard defined.
Here are complete listing of the classes design and implementations shown below. If you found this can or maybe useful you can deploy it yourself to your own C# project. Thanks.