Feeds:
Posts
Comments

Archive for August, 2008

i was reading a book head first design pattern, actually read that book many times, an excellent book. Sharing my details idea singleton design patter.

class diagram of Singleton design pattern

a singleton class is look like that
public class Singleton
{
private static Singleton UniqueInstance; //variable to hold one instance of the class Singleton
private Singleton(){}
public static Singleton getInstance()
{
if(UniqueInstance==null)UniqueInstance=new Singleton();
return UniqueInstance;
}
}
here the Singleton class constructor is private and it has only one static method to get it, that ensures that this class has only one instance, and provide a global point to access it.

Now think for multi threading…
what will happen??? suppose you have 2 threads, so 2 different instance of the object will be created.
WHATS THE SOLUTION ??? (more…)

Read Full Post »

fun with Javascript

I faced a problem to call 2 methods at the same time from body. and the solution is very simple. I wrote a script block at the end of the page look like that.

<SCRIPT LANGUAGE=”JAVASCRIPT”>

if(document.body.onload)

{

var existingOnLoad = document.body.onload;

document.body.onload = function()

{

existingOnLoad();

MyOwnMethod();

}

}

</SCRIPT>

Read Full Post »