Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
File1.cs
C#
namespace TestApp
{
    public partial class MainWindow :Window 
    {    
    }
}


File2.cs
C#
namespace TestApp
{
    public partial class MainWindow
    {
        A ob = new A();
    }

    public class A
    {}
    public class B
    {
    }
}



new modification to file2.cs
C#
namespace TestApp
{
    public partial class MainWindow
    {
        init()
        {
            Exchange ob = new Exchange();
            ob.set_tb(textbox1);
        }
    }

    public class A
    {}
    public class B
    {}
    
    public class Exchange : Window
    {
        TextBox tb1;
        
   // some hack to get textbox access
        public void set_tb(TextBox tcontrol)
        {
            tb1=tcontrol;
        }
    }

}


similarly there are lot of function i have to add in Exchange class which uses lots of variable available in main class.

is it a good option to take exchange class in main class.
Posted
Updated 29-Dec-11 22:02pm
v2

1 solution

Didn't quite follow the description, but as a general rule of thumb I'd avoid transferring UI objects between UI classes. Instead consider using properties and methods on your windows to transfer just needed information and to execute functionality. IMO even better if you could separate the UI from the data and from the logic to separate classes. This way the maintainability and robustness of the program would be better.
 
Share this answer
 
Comments
01.mandar 30-Dec-11 4:22am    
i had created a application some what like

namespace TestApp
{
public partial class MainWindow
{
A ob = new A();
B ob2 = new B();
}

public class A
{}
public class B
{}
public class Exchange
{}
}

every thing was running fine..
now suddenly i have to add some functionality in Exchange class like access some UI element(which even was working fine) but it starting to become hectic to manage many elements and data structure as the dependency started to grow on main class

is it a better approach like

___placing all classes in main class
namespace
{
public partial class MainWindow
{
A ob = new A();
B ob2 = new B();

public class A
{}
public class B
{}
public class Exchange
{}

}
}

or make distribute class operation into small function


namespace
{
public partial class MainWindow
{
//// all share variables


void fun_A
{}
void fun_B
{}
void Exchange_fun1()
{}
void Exchange_fun2()
{}

}
}


which approach will be better ?

.
Wendelius 30-Dec-11 13:34pm    
I would use the latter approach and pass only real values in the methods, not controls at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900