2 Replies Latest reply on Aug 27, 2010 10:07 PM by jschellSomeoneStoleMyAlias

    help: create a Factory when subclass constructors have different signatures


      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) { ... }