ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Builder pattern. 빌더
    DesignPattern/Creational Patterns 2013. 10. 25. 14:24

    Builder pattern. 빌더

     

    - 여러 특성을 가진 객체의 생성과 표현을 분리하여, 동일한 과정을 통해 다른 특성을 가진 객체를 만든다.

    빌더는 추상 팩토리와는 달리 객체의 다형성을 사용한다.

    수많은 생성자를 사용하고, 단계적으로 각각의 초기화 변수들을 이용하여 생성된 각각의 객체를 반환한다.

     

    1) 구조

    Builder Structure

    2) Pseudocode

     

    class Car is
      Can have GPS, trip computer and a various number of seaters. Can be a city car, a sport car or a cabriolet.

    class CarBuilder is
      method getResult() is
          output: a Car with the right options
        Construct and return the car.

      method setSeaters(number) is
          input: the number of seaters the car may have.
        Tell the builder the number of seaters.

      method setCityCar() is
        Make the builder remember that the car is a city car.

      method setCabriolet() is
        Make the builder remember that the car is a cabriolet.

      method setSportCar() is
        Make the builder remember that the car is a sport car.

      method setTripComputer() is
        Make the builder remember that the car has a trip computer.

      method unsetTripComputer() is
        Make the builder remember that the car does not have a trip computer.

      method setGPS() is
        Make the builder remember that the car has a global positioning system.

      method unsetGPS() is
        Make the builder remember that the car does not have a global positioning system.

    Construct a CarBuilder called carBuilder
    carBuilder.setSeaters(2)
    carBuilder.setSportCar()
    carBuilder.setTripComputer()
    carBuilder.unsetGPS()
    car := carBuilder.getResult()
     

     

     

    댓글

code by jaguarcode.