This discussion is archived
2 Replies Latest reply: Aug 27, 2010 3:07 PM by jschellSomeoneStoleMyAlias RSS

help: create a Factory when subclass constructors have different signatures

843853 Newbie
Currently Being Moderated
Hi,

How can I create a Factory class when the subclass constructors have different signatures?

For example, I would like to create a DataObjectFactory, where DataObject is an interface, and the subclasses consist of File, Collection and Block, but the constructor of each subclass is different. What would the Factory look like?

Would the following be good enough?
public class DataObjectFactory {
    ...
    public static DataObject createFile(String filename, String md5sum, long size, Date creationDate) { ... }

    public static DataObject createCollection(String collectionName, Date creationDate) { ... }

    public static DataObject createBlock(String blockContents) { ... }

}
Thanks.