Let's say I have 3 classes:
Main class, class A, class B
and let's also say that class B has a method which needs data from class A. (the data is actually a dataview object).
objects instances of class A and class B are created in the main class regardless of the above (for them to be created in general)
what would be the best way to reach the dataview object of class A from class B?
Should I make the dataview object internal? should I make it static? should I make it internal static?
I've learned to create properties in cases like these and just "get" the object, but since it's the main form (and not Class B) which creates an object of Class A, I can't reach that property from class B.
Edit, here is a demo code:
Class Main
{
A a = new A();
B b = new B();
a.doingAClassStuff(); //Not possible unless Class A is set to public or the method is set to internal (classes are internal by default)
b.doingBClassStuff(); //Likewise
//need to get the dv object here.
//dv.rows[1].foo = bar;
}
Here above in the main class I need to get the dv object from Class B.
//each class exist in a different class file (.cs file) inside the project
Class A
{
doingAClassStuff()
{
MessageBox.Show("Hello From Class A!");
}
//here access to the dv object is also needed.
//dv.rows[5].foo = something;
}
Class A also needs to get the dv object of Class B!
//in another file as well
Class B
{
DataView dv = new Dataview(datatable1)
doingBClassStuff()
{
MessageBox.Show("Hello From Class B!");
}
}
My notes:
Making "dv" only "Internal" will not make it visible.
Making "dv" "Internal Static" will make it visible and I can work with that but I am not sure "static" has no Cons, I am not creating more than 1 instance of each class (if it matters).
I tried setting properties with "get" and get it but since the properties are public and I couldn't set them to "internal" are they public to outside of the assembly as well?
Many Thanks!