1 Reply Latest reply on Aug 29, 2011 7:34 PM by jschellSomeoneStoleMyAlias

    DAO Factory pattern

      If i have two or more table in DB say Customer, Product and Sales. I am using DAO factory pattern as follow.

      1. Creating Interface and Implementation classes for each table with CRUD and operations.
      2. In factory side I am creating the factory Interface with method to create each table Interface.
      3. Then implemented class will do lookup and have datasource setup.

      Now my question is on point 2 where I have interface with methods to create the table interface like

      public interface MainFactoryInterface {

      public CustomerIF createCustomerIF();

      public ProductIF createProductIF();

      public SalesrIF createSalesIF();

      public DataSource getDataSource();


      Is this a right way to do?
        • 1. Re: DAO Factory pattern
          If you have a factory then it is not an interface. If it just a class.
          If you want to create an abstract factory then it requires an interface for the factory.

          I wonder why you are using a factory at all. And if you are using a factory then it would be really odd to have it exposing the data source, since presumably, that would be the very thing that would complicate the creation of the DAOs in the first place. Of course the reason one uses a factory is because creation is complicated.

          So ignoring that then specific comments.
          public CustomerIF createCustomerIF();
          Nope. It should be called CreateCustomer() because you are not creating an interface.
          interface MainFactoryInterface
          public CustomerIF createCustomerIF();
          I am not a great fan of using 'IF' like that but I am however a great fan of consistency. So either name all of your interfaces with 'Interface' or with 'IF'. One or the other not both.
          Is this a right way to do?
          Excluding everything above then yes.