• Post Reply Bookmark Topic Watch Topic
  • New Topic

single instance of class accessed by other classes without providing a reference  RSS feed

 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wonder if this was possible...

I've written a factory which is instantiated by the main application. I also have some threads that want to use that factory to create some DAO's. is there a way for the thread to access the factory without explicitly giving the thread a reference to it upon its creation?

Thanks.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Singletons and static creational methods both come to mind.

Both of those have drawbacks with flexibility and extensibility. You wanted to rule out "injecting" a factory into the classes that need them. Any particular reason? That gives a better dependency picture than the samples above and makes it easier to slip in alternative factories if need be.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!