001package template.series2; 002import enumeration2.Op; 003interface Series { 004 void next(); 005 void print(); 006} 007class SeriesFactory { 008 private SeriesFactory() {} 009 public static Series newArith() { return new ConcreteSeries(Op.ADD); } 010 public static Series newGeom() { return new ConcreteSeries(Op.MUL); } 011} 012class ConcreteSeries implements Series { 013 int x; 014 int y = 1; 015 public void next() { x++; y = op.eval(y,2); } 016 public void print() { System.out.println("x=" + x + "; y=" + y); } 017 Op op; 018 ConcreteSeries(Op op) { this.op = op; } 019} 020 021public class Main { 022 public static void main(String[] args) { 023 Series x = SeriesFactory.newGeom(); 024 x.next(); 025 x.next(); 026 x.print(); 027 } 028}