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

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