Objects that can be shared across multiple classes
I have a project that has 11 classes. Now each class refers to the tasklayer (another set of multiple classes) and instantiates them everytime.
Now I don't want to create a separate set of objects for each of these classes in MyProj.
I want to create a single of set of objects of the tasklayer classes and reference these in my MyProj classes.
Can anyone please tell me how to do that? Can I use Singleton here? Will the same object of the Singleton class be referred in all of MyProj classes?
Ananya Choudhury, Jul 04, 2010
In MyProj, create a separate shared class ( Class _D )
Expose properties from which return objects of A,B,C
In constructor of class _D, create objects of A,B,C..
So when class _D gets instantiated, its created objects of A,B, C.
Since _D is shared class, single objects of _D,A,B,C are in scope.
Shailendra Baghel, Jul 05, 2010