Business interfaces and packages When I last did a lot of Java programming, I'd do this:


All classes in a package would be default (package) visibility.
Each package would have a public PackageNamePack factory class, e.g. BusinessPack. 
And the package would have a number of interfaces.
The package factory would have methods like newBusiness(...) which would instantiate new BusinessImplWhatever objects, cast as a Business interface.


The factory class:

package io.eaternet.adapters.framework;

public class FrameworkPack {
    public static Business newBusiness(String name, String address, String city, String zipcode, String origKey) {
        return new BusinessImpl(name, address, city, zipcode, origKey);
    }

    public static Inspection newInspection(String origKey, String businessOrigKey, String score, String date) {
        return new InspectionImpl(origKey, businessOrigKey, score, date);
    }
}


An interface:

package io.eaternet.adapters.framework;

public interface Business {
    public String getName();
    public String getAddress();
    public String getCity();
    public String getZipcode();
    public String getOrigKey();
}


A package-visibility implementation class:

package io.eaternet.adapters.framework;

class BusinessImpl implements Business {
    String name, address, city, zipcode, origKey;

    BusinessImpl(String name, String address, String city, String zipcode, String origKey) {
        this.name = name;
        this.address = address;
        this.city = city;
        this.zipcode = zipcode;
        this.origKey = origKey;
    }

    public String getName() { return name; }
    public String getAddress() { return address; }
    public String getCity() { return city; }
    public String getZipcode() { return zipcode; }
    public String getOrigKey() { return origKey; }
}


I've started a new Java library which follows this pattern, and am wondering if it still make sense. This particular code is part of a CSV parser, which is why everything is a string.
FrameworkPack is not a factory.
Business declares methods that automatically are public, remove the word public.
BusinessImpl looks like a ReadOnly-Class, declare the fields as final.
If FrameworkPack shall never be instanicated, create a private Constructor and make the class final so noone is able to create a instance.


You can use the Abstract-Factory and Singleton- pattern by ease.

public interface Framework {
    Business newBusiness(String name, String address, String city, 
                         String zipcode, String origKey);
    Inspection newInspection(String origKey, String businessOrigKey, 
                             String score, String date);
}
public interface Business {
    String getName();                   
    String getAddress();                
    String getCity();                   
    String getZipcode();                
    String getOrigKey();                
}
public final class FrameworkPack implements Framework {
    private FrameworkPack(){};
    private static final FrameworkPack INSTANCE; 
    public static final FrameworkPack getInstance(){
        if (INSTANCE==null) {
           ensureExistingInstance();
        }
        return INSTANCE;
    }
    private synchronized void ensureExistingInstance(){
       if(INSTANCE==null){
         INSTANCE = new FrameworkPack();
       }
    }

    public BusinessImpl newBusiness(String name, String address, String city, 
                         String zipcode, String origKey){
      return new BusinessPack(name, address, city, zipcode, origKey);
    }
    ...
}
public final class BusinessPack {
    private final String name;
    private final String address;
    private final String city;
    private final String zipCode;
    private final String origKey;
    BusinessPack(String name, String address, String city, 
                         String zipcode, String origKey) {
      this.name = name;
      this.address = address;
      this.city = city;
      this.zipcode = zipcode;
      this.origKey = origKey;
    }
    ...
}