I'm a bit fuzzy on the best way to solve the problem of needing a list for each of my business objects that implements some overridden functions.
Here's the setup: I have a baseObject that sets up database, and has its proper Dispose() method All my other business objects inherit from it, and if necessary, override Dispose()
Some of these classes also contain arrays (lists) of other objects. So I create a class that holds a List of these. I'm aware I could just use the generic List, but that doesn't let me add extra features like Dispose() so it will loop through and clean up.
So if I had objects called User, Project and Schedule, I would create UserList, ProjectList, ScheduleList.
In the past, I have simply had these inherit from List<> with the appropriate class named and then written the pile of common functions I wanted it to have, like Dispose().
this meant I would verify by hand, that each of these List classes had the same set of methods. Some of these classes had pretty simple versions of these methods that could have been inherited from a base list class.
I could write an interface, to force me to ensure that each of my List classes has the same functions, but interfaces don't let me write common base functions that SOME of the lists might override.
I had tried to write a baseObjectList that inherited from List, and then make my other Lists inherit from that, but there are issues with that (which is really why I came here). One of which was trying to use the Find() method with a predicate.
I've simplified the problem down to just a discussion of Dispose() method on the list that loops through and disposes its contents, but in reality, I have several other common functions that I want all my lists to have.
What's the best practice to solve this organizational matter?
--------edit---added an example class that I'm trying to clean up with a better approach --This next code block is from my AppVarList class, which inherits straight from List. Right now I've got a mixture of styles on these lists, because I'm trying to find the best way to manage all these and consolidate the code:
[Serializable]
public class AppVarList : List<AppVar>
{
private bool is_disposed = false;
private bool _NeedsSaving = false;
// Returns the AppVar, by name
public AppVar this[string index]
{
get { return this.Find(f => f.Key == index); }
set { this[this.FindIndex(f => f.Key == index)] = value; }
}
public AppVarList() { }
// instantiates the object and connects it to the DB
// and populates it
internal AppVarList(ref DBLib.DBAccess DA)
{
DataSet ds =
AppVar.SQLSelect(ref DA, 0, 0, false, "", "", "", "");
foreach (DataRow dr in ds.Tables[0].Rows)
{
this.Add(new AppVar(ref DA, dr));
}
// Destroy the dataset object
if (ds != null)-