Паттерн: Строитель (Builder)
Исходник: RotatingPartCountBuilder.java, язык: java [code #418, hits: 8467]
автор: this [добавлен: 30.05.2007]
  1. package builder;
  2.  
  3. import abstractFactory.Car;
  4.  
  5. public class RotatingPartCountBuilder extends CarBuilder {
  6. private int count = 0;
  7. private final int inSkeleton = 10;
  8.  
  9. public RotatingPartCountBuilder(int initialCount) {
  10. count = initialCount;
  11. }
  12.  
  13. public Car GetCar() {
  14. return null;
  15. }
  16.  
  17. public void MakeCar() {
  18. count += inSkeleton;
  19. }
  20.  
  21. public void MakeDoor(int side, int position) {
  22. count += 3;
  23. }
  24.  
  25. public void MakeEngine(int position) {
  26. count += 100;
  27. }
  28.  
  29. public void MakeWheel(int side, int position) {
  30. count += 2;
  31. }
  32.  
  33. public int getCount() {
  34. return count;
  35. }
  36.  
  37.  
  38. public void Reset(int initialCount) {
  39. count = initialCount;
  40. }
  41.  
  42. }
Сущность ConcreteBuilder
Реализация косвенного строителя строителя, выполняющего непрямые, но вспомогательные функции.
В данном случае: подсчет движущихся частей в автомобиле.

Используемые классы и интерфейсы автомобилей приведены при реализации абстрактной фабрики.
Тестировалось на: java 1.5.0_04

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