I am developing a swing app, where I have a Factory class which provide Component keeping Singleton in mind. Like:
public final class ComponentFactory {
private static LibraryFrame libraryFrame;
private static LibraryTableScrollPane libraryTableScrollPane;
public static synchronized LibraryFrame getLibraryFrame() {
if (libraryFrame == null) {
libraryFrame = new LibraryFrame();
}
return libraryFrame;
}
public static synchronized LibraryTableScrollPane getLibraryTableScrollPane() {
if(libraryTableScrollPane == null) {
libraryTableScrollPane = new LibraryTableScrollPane(getLibraryTable());
}
return libraryTableScrollPane;
}
}
I am using this component as:
add(ComponentFactory.getLibraryTableScrollPane())
Also I make a ListenerFactory class which provides various Listeners of Swing/AWT.
Is this pattern has any flaws? Can I use a same component or listener with two concurrently visible parent component?
Thanks in advance.