HI,
Today is my first day at this wonderful forum.I wanted to ask How to :
Make a class globally accessible to all the classes ?I come from the C back ground so I
am thinking like this -- I want to use the class (say classGlobal) from the other files(Classes) I am doing something like this :
namespace Namspce
{
public class class1
{
/* Declaring the classGlobal as static */
public static classGlobal cg = new classGlobal();
public void method()
{
/* some updation to members of this class members(variables inside methods)*/
cg.method1();
cg.method2();
cg.method3();
/* Creating another class instance to accss this classGlobal members */
classOther co = new classOther();
/* Now here control goes to classOther.cs where I am supposed to use the class cg(its updated members - variables)*/
/* Remember that due to too much parameter passing i dont want to pass the whole class variable cg to "co.somemethod()" */
co.somemethod();
}
}
}
classOther.cs
namespace Namspce
{
class classOther
{
public void somemethod()
{
/* accessing the class which I have declared static */
class1.cg.method4();
}
}
}
classGlobal.cs
namespace Namspce
{
public class classGlobal
{
private string var1;
private string var2;
private string var3;
private string var4;
/* Class definition */
public void method1()
{
/* updating var1 here */
}
public void method2()
{
/* updating var1 and var2 here */
}
public void method3()
{
/* updating var1,var2 and var3 here */
}
public void method4()
{
/* updating var1,var2,var3 and var4 here */
}
}
}
So am I doing it correct,For the OOPS concept is this approach correct?
Kindly spark the debate.?
Best Regards