Use class instance over solution

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there..

I have a question about instance usage...
I created a VStudio 2003 solution within 3 projects as follow:

1) Proj One: Main form
2) Proj Two: User Control
3) Proj Three: Class

I need to instance the class in project three ad use the same instance in
the user
control. i.e. I need to set a property of class in project three and use it
in the
User Control

Any ideas??

I hope to be quite clear...
Thanks in advance
 
Hi,

Use the Singleton design pattern for the class. In essence, you keep the
sole instance of the class in a private static variable of the class, you
make the class constructor private, and you have a public static property
called Instance returning the sole instance. The code of the Instance
property checks whether the instance has been created, and if not, creates
it and returns the reference to the instance to the caller.
 
Hi,

Remember one thing, the projects are a logic split intended only to
facilitate the development , at runtime you only have one application no
matter how you divided it at development time.
That said, if you want to have one instance in the running application you
should use the Singleton pattern, or make the members static.


Cheers,
 
Back
Top