Views: 7.3K
Replies: 1
Archived
|
Objects that can be shared across multiple classesHi,
I have a project that has 11 classes. Now each class refers to the tasklayer (another set of multiple classes) and instantiates them everytime. For example: TaskLayer: contains 3 classes under same namespace. A.cs ------ public class A{} B.cs --------- public class B{} C.cs -------- public class C{} MyProj: my classes needs to refer to tasklayer classes _A.cs ------ using Tasklayer; class _A { A a = new A(); B b = new B(); C c = new C(); } _B.cs ----- using Tasklayer; class _B { A a = new A(); B b = new B(); C c = new C(); } _C.cs ------ using Tasklayer; class _C { A a = new A(); B b = new B(); C c = new C(); } 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? Thanks. Ananya Choudhury, Jul 04, 2010
|
|
Reply 1In 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. Thanks, Shailendra Shailendra Baghel, Jul 05, 2010
|