Saturday, June 18, 2005

SHE - Rabindra Nath Tagore

She
She who ever had remained in the depth of my being,
in the twilight of gleams and of glimpses;
she who never opened her veils in the morning light,
will be my last gift to thee, my God, folded in my final song.
Words have wooed yet failed to win her;
persuasion has stretched to her its eager arms in vain.
I have roamed from country to country keeping her in the core of my heart,
and around her have risen and fallen the growth and decay of my life.
Over my thoughts and actions, my slumbers and dreams,
she reigned yet dwelled alone and apart.
Many a man knocked at my door and asked for her
and turned away in despair.
There was none in the world who ever saw her face to face,
and she remained in her loneliness waiting for thy recognition.


This is a poetry by Takhur (R.N. Tagore)
Whom did he write about? she?? who is she?? Was she his first love? first crush??. Who was she?? Was she a widow?? was she married?? Was Tagore's first love a married woman or a widow?? Well great people in the world have great thoughts(generally different from the normal man of the time.). Widow marriage/love was not accepted for the society in India at that point of time. So was Tagore in Love of a lady who was married? or may be a widow? whose annonimity was a security for the lady?? She was so beautiful and she was so pretty , Tagore even thought that it will be a gift to GOD which he desires. Was she so beautiful?? I she more beautiful than todays Aish?? I am sure she was... I wish Tagore had named her. Some name. like Monalisa... hmm no an Indian name .. like "PARI" . Just thinking , if he would have given the name , it would be the most popular name in Indian History rather than "MAYA" which is the post popular baby name in Indian Americans.... I hope he(Tagore) was more open than hiding his feelings for the pretty widow he loved in his deep core of heart...


-- This is my view, my space, if you like it please leave a message if not dont create a big scene as every human in this planet has a right to express his/her view and not be screwed for that...

Thank YOU .. June 19 , 2005 12:20 AM (After 3 pegs of Glenfidditch ..)

Sunday, May 15, 2005

Creating Javascript Dynamic Tabs and Layer

This is an example where you can create your tabs and layers dynamically. Then move from one tab to another which displays the associated layer.

Generally in the web we can find how to dynamically move from one tab to another, but not how to dynamically create tabs and layers . I had to do this for one of my project and therefore thought to add this for reference.

This example works Netscape, IE and Firefox. This uses the Javascript DOM which is a web standard to create the dynamic layers.

The code is pretty simple and it has been arraged properly for reuse and customization. Click here to see the working version and get the code .For more questions u can email me to puspendu_p@yahoo.com

Thanks, Please drop by your comments.

Friday, April 29, 2005

Factory Pattern

I have been reading lately about the Factory design pattern in Java. Most of the text i read in web describes what Factory pattern is but not HOW to use the design pattern? Or describe how it helps in future changes to your application . I felt a need to add a note on it on my first blog here.

How to use a Factory Design Pattern ? How it helps in future changes to your application? Use Case (Where to use? - Think about a requirement where you need to create documents. Your application uses a document object . You can have methods like - read(),write() methods or any other methods u need in document object. But there are different ways (implementation) u can create a document object. For example creating a document object from a file, from an input stream. But its not limited to only these 2 implementations. There could be other ways to create document like getting it from other application etc. So you want to develop your application such that it has 2 implementation of creating a document and support future implementation of document creation.

Here is how your client application should look like.

public class DocumentUser
{
Document doc ;
DocumentFactory docFactory ;
public Document getDocument()
{
return doc;
}

public void setDocument()
{
return docFactory.createDocument();
}

public void setDocFactory(DocumentFactory docFactory)
{
this.docFactory = docFactory;
}

public static void main()
{
DocumentUser docUser = new DocumentUser();
DocumentFactoryFile docFactory = new DocumentFactoryFile();
//DocumentFactoryStream docFactory = new DocumentFactoryStream();
docUser.setDocumentFactory(docFactory);

Document doc = docUser.getDocument();
doc.read();

}
}


In the above class we havent actually created the document object inside the DocumentUser, instead have moved the actual instantiation to the DocumentFactory classes. And we have made the DocumentFactory object as a class variable of the DocumentUser object. In doing the above 2 changes we have made our DocumentUser classs independent of the Document Creation implementation. You can add or change any document implementation to the DocumentUser (as shown in the main method - just uncomment the commented line and comment the upper line.) So now your application(DocumentUser) is independent of Document creation or implementation.

How to implement Factory Design Pattern?
So now since you know how to use factory design pattern , you can go ahead and create your first implementation of Factory Design Pattern. There are lot information in the web to explain how to create the Factory design pattern, but just for your convinience and my reference i am writing the next block.
There are basically 2 ways to implement the Factory Design pattern.
1) Concrete Class
In this implementation you create a BaseFactory Class. Have a create() method with default implementation. Then any sub classes extending from the BaseFactory class can over-ride the create method if needed. Else it will use the default implementation of the BaseFactory Class. This implementation is used when you know the default implementation of the object creation.

public class BaseDocumentFactory
{
public Document createDocument()
{
return new DocumentBase();
}
}


public class DocumentFactoryFile extends DocumentFactory
{
public Document createDocument()
{
return new DocumentFile();
}
}
public class DocumentFile implements Document
{
...
...
...

public String read()
{
System.out.println("File Implementation of document.");
}

}

public class DocumentBase implements Document
{
...
...
...

public String read()
{
System.out.println("Base Implementation of document.");
}
}


2) Abstract Class
In this implementation you create an abstract class with an abstract method ex - create() . The classes extending from the the abstract class actually does the creations of the object. This type of implementation should be used when the base class is not aware of the implementation ans there is no default implementation .

public abstract class DocumentFactory
{
public abstract Document createDocument();
}

public class DocumentFactoryFile extends DocumentFactory
{
public Document createDocument()
{
return new DocumentFile();
}
}

public class DocumentFile implements Document
{
...
...
...


public String read()
{
System.out.println("File Implementation of document.");
}
}


Well you must be thinking cant we use an "Interface" and all Factory Classes must implement the create method. Answer - Yes you can. I think its just a variant of the Abstract Class type.


-ANY COMMENT IS APPRECIATED!!!!!