01
02
03
04
05
06
07
08
09
10
11
package factory.shape3;
public class ShapeFactory {
  private ShapeFactory() {}
  static public Shape newInstance(String selector) {
    if ("Ellipse".equals(selector))   return new Ellipse();
    if ("Circle".equals(selector))    return new Ellipse();
    if ("Rectangle".equals(selector)) return new Rectangle();
    if ("Square".equals(selector))    return new Rectangle();
    throw new IllegalArgumentException();
  }
}