I
ittium
Group,
I have two classes
Class A //At present only one instance of this class is needed
Class B //Multiple instances of this class will require single
instance of Class A.
I have two designs here
1. Define A as singleton so that wherever needed it can be accessed
using getInstance method. I want to avoid this design since my system
is multihreaded.
2. In Class B define a ** reference** member of type A. First
construct A and during construction of B pass instance of A. Here I
have flexibility of creating more instances of A in future.
Which approach is better. Is there anything better than this.
thanks
Ittium
I have two classes
Class A //At present only one instance of this class is needed
Class B //Multiple instances of this class will require single
instance of Class A.
I have two designs here
1. Define A as singleton so that wherever needed it can be accessed
using getInstance method. I want to avoid this design since my system
is multihreaded.
2. In Class B define a ** reference** member of type A. First
construct A and during construction of B pass instance of A. Here I
have flexibility of creating more instances of A in future.
Which approach is better. Is there anything better than this.
thanks
Ittium