Geeks With Blogs
Madhawa Learns To Blog : C#, Java .net, c#, java,sql, OOAD and more mad memory dumps...

Google announced that they have opensourced the Google Singleton Detector, or GSD. Simply GSD is a tool which analyzes Java byte code and detects the use of Singletons.

As they say:

It's not quite as simple as that, however. First, GSD doesn't only detect singletons; it detects four different types of global state, including singletons, hingletons, mingletons and fingletons.Second, it outputs a graph with all these different types of static state highlighted, and shows all the classes that are directly dependent on them. The point of this tool is to allow you to see all of the uses of global state inside a project, as well as how they are all interrelated. Hopefully you'll be able to locate global state that is heavily depended on and remove it.

Well... Now you might think what’s wrong with the good old singleton pattern which we always use freely in every project?  Singleton pattern is the first pattern I learned and used.  

Actually there are some problems with singletons.

Major problem is that it’s hard to write unit tests if you are using singleton classes. How that could be? Well... If your unit tests are really good those should be loosely coupled. That’s mean you should be able to execute your tests without any proper order and yet those tests should be passed. But if your class had used singleton class one method can alter a state of sth in the singleton class and that would effects in the other tests. That’s make your tests are tightly coupled with each other. So you should have to have an order in executing your tests or you should reset your singleton objects in each test.

Ok folks, let’s dig into further on this problem and of cause will try to find some workarounds, in my next blog post.


Posted on Thursday, July 26, 2007 1:17 AM Java , Architecture | Back to top

Comments on this post: Google Singleton Detector

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Madhawa Karunaratne | Powered by: