Link to home
Start Free TrialLog in
Avatar of Todd710
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;
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can't see any problems.
Really, the approach is very similar to a singleton pattern.
You just added resetting to it.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Todd710
Todd710

ASKER

Thanks for the affirmation.  I just wanted to be sure I was coding this correctly.