Todd710
asked on
Is there problems with using a class like this?
I want to extend the scope of a particular object to all of my classes. This is a single threaded application. Is this a bad approach? and if so what suggestions would you have for me(i.e. examples)? What if any are is the downside to this approach? What is the normally accepted approach to this issue?
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using nsoftware.IBizQB;
namespace myExampleClass
{
class Example
{
private bool InitializeQBCustomer()
{
bool bSuccess = false;
try
{
if (AC.CustomerMain == null)
{ AC.CustomerMain = new Customer(); }
else
{ AC.CustomerMain.Reset(); }
bSuccess = true;
}
catch
{
//handle problems
}
return bSuccess;
}
}
}
//In separate class
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using nsoftware.IBizQB;
namespace myExampleClass
{
class AC
{
public static nsoftware.IBizQB.Customer CustomerMain;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the affirmation. I just wanted to be sure I was coding this correctly.
Really, the approach is very similar to a singleton pattern.
You just added resetting to it.