1 interface PriceParams { 2 public static final int CHILDRENS = 2; 3 public static final int REGULAR = 0; 4 public static final int NEW_RELEASE = 1; 5 } 6 7 class ChildrensPrice extends Price { 8 int getPriceCode() 9 { 10 return CHILDRENS; 11 } 12 } 13 14 class NewReleasePrice extends Price { 15 int getPriceCode() 16 { 17 return NEW_RELEASE; 18 } 19 } 20 21 class RegularPrice extends Price { 22 int getPriceCode() 23 { 24 return REGULAR; 25 } 26 } 27 28 abstract class Price implements PriceParams{ 29 abstract int getPriceCode(); 30 public static Price getInstance(int priceCode) 31 { 32 Price result = null; 33 switch (priceCode) { 34 case CHILDRENS: 35 result = new ChildrensPrice(); 36 break; 37 case REGULAR: 38 result = new RegularPrice(); 39 break; 40 case NEW_RELEASE: 41 result = new NewReleasePrice(); 42 break; 43 default: 44 throw new IllegalArgumentException(); 45 } 46 return result; 47 } 48 } 49