I have two classes, one has a lot of properties and the other has a couple. I need to reference a few of the properties of the larger class in the smaller class, but I'm wondering if it would be better to just pass the values down individually. Example:
public class LargeClass
{
private string _var1;
private string _var2;
private string _var3;
//...
private string _var20;
//stuff
}
public class SmallClass
{
private LargeClass _largeclass;
private string _var1;
public SmallClass(LargeClass LargeClass)
{
_largeclass = LargeClass;
_var1 = _largeclass.Var1 + _largeclass.Var2;
}
}
Or, I could do this for the small class and pass the values I need in directly:
public class SmallClass2
{
private string _var1;
private string _var2;
private string _var3;
public SmallClass2(string Var1, string Var2)
{
_var1 = Var1;
_var2 = Var2;
_var3 = _var1 + _var2;
}
}
Basically, my question is which one of these uses up less space (both while running and if serialized)?
Update: I was able to rewrite my classes so that the smaller class objects referenced their parent objects and found that it definitely did use less space when serialized. Obviously, this result is case by case, but for my code I basically changed it from each instance of the small class storing a file path as a string to having the class capable of creating the path string on the fly using references to the parent objects.
The resulting serialized data file was 55% smaller.