Паттерн: Абстрактная фабрика (Abstract Factory)
Исходник: Vaz2110.java, язык: java [code #406, hits: 8414]
автор: this [добавлен: 24.05.2007]
  1. package abstractFactory.rusFleet;
  2.  
  3. import abstractFactory.Car;
  4.  
  5. public class Vaz2110 extends Car implements Cloneable {
  6. private final String factoryId;
  7. private boolean injector;
  8.  
  9. public Vaz2110(String number, final int modelNum,
  10. boolean injector) {
  11. super(number, 4, 4, 5, 180);
  12. this.factoryId = "21" + String.valueOf(modelNum);
  13. this.injector = injector;
  14. }
  15.  
  16. public String getFactoryId() {
  17. return factoryId;
  18. }
  19.  
  20. public boolean isInjector() {
  21. return injector;
  22. }
  23.  
  24. // equals/hashCode/toString >>
  25. public boolean equals(Object o) {
  26. if (!(o instanceof Car)) {
  27. return false;
  28. }
  29.  
  30. if (!(o instanceof Vaz2110)) {
  31. return o.equals(this);
  32. }
  33.  
  34. Vaz2110 other = (Vaz2110) o;
  35.  
  36. return (super.equals(o) &&
  37. other.injector == injector &&
  38. other.factoryId == factoryId);
  39. }
  40.  
  41. public int hashCode() {
  42. int res = super.hashCode();
  43. res = res * 37 + (injector ? 1 : 0);
  44. res = res * 37 + factoryId.hashCode();
  45. return res;
  46. }
  47.  
  48. public String toString() {
  49. String res = super.toString();
  50. res += ", injector=" + injector;
  51. res += ", factoryId=" + factoryId;
  52. return res;
  53. }
  54.  
  55.  
  56.  
  57. }
Сущность ConcreteProduct
"Десятка" - легковой русский автомобиль
Тестировалось на: java 1.5.0_04

+добавить реализацию