I have a class file that is setup similar to the structure below. Basically objALLData is my main data object (it collects the information from the user and inserts it into the DB).
However, in objAllData I have a need to have the option of a collection of objSubSet1 and/or objSubSet2. However, both of these subsets do not need to be public. All I need them to do is to populate and then in the objAllData I would add them to a collection (specified in objAllData).
When I try to make the subset classes private I was getting an inconsistent accessibility error. According to my research I needed to make them public. However, I really don’t want anyone to know about these objects except objAllData. Does that make sense?
Any idea on how I can achieve what I think I want? 🙂
public class objAllData
{
List<objSubSet1> ss1 = new List<objSubSet1>();
List<objSubSet2> ss2 = new List<objSubSet2>();
public List<objSubSet1> addSS1toCollection()
{
objSubSet1 myOBJSS1 = new objSubSet1();
myOBJSS1.property = "";
ss1.add(myOBJSS1);
return ss1;
}
}
public class objSubSet1
{
<property>
<property>
<property>
}
public class objSubSet2
{
<property>
<property>
<property>
}
Since your add method returns the list, the user needs to have some visibility to the type you are returning. The easiest way to not fully expose the real object type is to create an interface.
This way the user only has access to the methods defined by
Thingwhere asObjAllDatahas full access to the real object type.NOTE:
Your sample code has a number of syntax errors that will keep your code from compiling.
Class definitions do not have parenthesis in them
Function definitions have to specify the variable type they are returning, not the variable name.
You are also missing a semi-colon after your return statement.