Паттерн: Абстрактная фабрика (Abstract Factory)
Исходник: Bus.java, язык: java [code #402, hits: 8724]
автор: this [добавлен: 24.05.2007]
  1. package abstractFactory;
  2.  
  3. public abstract class Bus extends Car {
  4. private int passengerNum;
  5. private boolean twoStage;
  6.  
  7.  
  8.  
  9. public Bus( String number,
  10. int doorNum, int wheelNum,
  11. int seetNum, int maxSpeed,
  12. int passengerNum, boolean twoStage) {
  13.  
  14. super(number, doorNum, wheelNum, seetNum, maxSpeed);
  15. this.passengerNum = passengerNum;
  16. this.twoStage = twoStage;
  17. }
  18.  
  19. public int getPassengerNum() {
  20. return passengerNum;
  21. }
  22. public void setPassengerNum(int passengerNum) {
  23. this.passengerNum = passengerNum;
  24. }
  25. public boolean isTwoStage() {
  26. return twoStage;
  27. }
  28. public void setTwoStage(boolean twoStage) {
  29. this.twoStage = twoStage;
  30. }
  31.  
  32. // equals/hashCode/toString >>
  33. public boolean equals(Object o) {
  34. if (!(o instanceof Car)) {
  35. return false;
  36. }
  37.  
  38. if (!(o instanceof Bus)) {
  39. return o.equals(this);
  40. }
  41.  
  42. Bus other = (Bus) o;
  43.  
  44. return (super.equals(o) &&
  45. other.twoStage == twoStage &&
  46. other.passengerNum == passengerNum);
  47. }
  48.  
  49. public int hashCode() {
  50. int res = super.hashCode();
  51. res = 37 * res + (twoStage ? 1 : 0);
  52. res = 37 * res + passengerNum;
  53. return res;
  54. }
  55.  
  56. public String toString() {
  57. String res = super.toString();
  58. res += ", twoStage=" + twoStage;
  59. res += ", passengerNum=" + passengerNum;
  60. return res;
  61. }
  62. }
Сущность AbstractProduct
Абстракция автобуса
Тестировалось на: java 1.5.0_04

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