If you only ever want one instance of the object you are using use the
Singleton pattern and you will have no problems at all and no need to make
that method static.
I will look into the singleton pattern. That seems to make sense.
Just reading it i have no idea why you would do it that way anyway, it's
like you want to avoid using member variables or something?
Well, I instantiate an object in the Data Access layer that creates a
DataSet. There are a number of forms that need to perform CRUD operations
on that DataSet. So I can't instantiate another instance of that class
whenever I need to update the DataSet.
In an attempt to keep all data access in the DA layer, I make the DataSet a
public property of class that creates it and then go through a Builder class
to get objects (Arrays mostly) from the DataSet. I pass the objects back to
the calling forms, which can then bind controls to them. The Builder class
also handles updates to the DataSet, such as that addProject method (which
is called from a form).
As your method seems to be made to AddProject , it may be that you are
trying to use this class to spawn objects? if that is right look at the
Factory pattern as thats exactly what you need.
I think my builder class woud qualify as a Factory class.
But as i say singleton will make your whoe class static and you can always
access that one instance like this:
public class myClass
{
public static readonly myClass Instance = new myClass();
...}
At the top of the class to be singleton. Then access it from anywhere in
your app like this:
myClass.Instance.AddProject();
And you never do a myClass m = new myClass(); because the class always
uses one instance so it never needs more to be made as the one instance is
created the moment your app starts.
Does that help? i would advise you look up design petterns, they are of
immense use once you understand them.
Yes, that does help. But I'm wondering if I should use a Singleton or just
keep the DataSet a public property of the class that creates it. What's the
difference?