Solved

Is there problems with using a class like this?

Posted on 2009-04-06
4
210 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:Todd710
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 24082734
If your app is SINGLE threaded then there should be no problem at all...
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 24082779
Can't see any problems.
Really, the approach is very similar to a singleton pattern.
You just added resetting to it.
0
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 250 total points
ID: 24082801
Just in case - here is an interesting article on multythreaded singleton:

http://blogs.msdn.com/cjohnson/archive/2004/06/10/152179.aspx
0
 

Author Closing Comment

by:Todd710
ID: 31567287
Thanks for the affirmation.  I just wanted to be sure I was coding this correctly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Server Error 11 48
Error in script 11 48
C# MVC and a global static factory that never dies 4 49
Web Form VB.Net  import CSV 4 27
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now