You just need a standard server type. You don’t care how it’s built; you just tell the factory what “tier” you want.

  1. The interface
public interface EC2Instance {
    void start();
}
  1. The implementations
public class MicroInstance implements EC2Instance { /*...*/ }
public class ComputeOptimizedInstance implements EC2Instance { /*...*/ }
  1. The Factory (Making the decision)
public class InstanceFactory {
    public static EC2Instance createInstance(String tier) {
        return switch (tier.toLowerCase()) {
            case "free-tier" -> new MicroInstance();
            case "high-load" -> new ComputeOptimizedInstance();
            default -> throw new IllegalArgumentException("Unknown tier");
        };
    }
}
  1. Usage: One line, decision made for you.
EC2Instance server = InstanceFactory.createInstance("free-tier");