Alright, I wasn't sure how to phrase this title (since I know that sub-classes are generally referred to as inherited classes, which is NOT what I am referring to in my question (yes I know I’m inheriting methods from an abstract class in my example. That’s more to avoid code duplication here, and not really related to my question ), so I'm gonna give as best an example as I can.
I have a class object that has around 130 properties, supported by a private DataTable object in my winforms project. These majority properties will look up some column(s) in the DataTable (and possibly update said value in the DataTable in the future). Other properties use that DataTable value and perform a lookup against a database or dictionary. These are set up as properties because they will be bound to across several different userforms, and many of them will be evaluated throughout the codebase, so I wanted easy access to them.
Obviously, 130 properties is quite a bit. So I came up with a naming scheme to help organize them, but was wondering about further organization by category. The problem with this is that an inner class must now be initialized as an object (see code below), and I require access to the primary object's DataTable.
Example code:
// All subclasses will have these members to allow retrieval of data
Public Abstract Class DataMethods
{
protected DataTable table;
protected int Return_Int(string SearchCol) => // get value from datatable
protected string Return_String(string SearchCol) => // get value from datatable
protected bool Return_Bool(string SearchCol) => // get value from datatable
}
public sealed class ObjectToUseInProgram :DataMethods
{
// this inherits the Datatable object and methods to get data from it
public ObjectToUseInProgram(string LookupID)
{
table = {build the data table};
PG1 = new PropertyGroup_1(table);
}
public PropertyGroup_1 PG1 {get; private set;}
public sealed class PropertyGroup_1 :DataMethods
{
public PropertyGroup_1(DataTable tbl) { table = tbl; } //constructor
public Property_1 {get;} //retrieve value from ObjectToUseInProgram.table
}
}
The goal here is to be able to retrieve a property using ObjectToUseInProgram.PropertyGroup_1.Property_1
, but Property_1
gets its value from the DataTable stored within ObjectToUseInProgram
If I use the ref
keyword in PropertyGroup_1
's constructor, will that mean that PropertyGroup_1.table
will always use ObjectToUseInProgram.table
?
If in the future we implement the ability to perform 'Set' functions on the properties, they need to update the table for ObjectToUseInProgram
, that way we avoid having multiple property groupings each with their own table modifications.