www.webdeveloper.com
Results 1 to 3 of 3

Thread: [Pattern] (Prototype) There is an error in this exemple that i read on a book?

Threaded View

  1. #1
    Join Date
    Jan 2013
    Posts
    84

    Question [Pattern] (Prototype) There is an error in this exemple that i read on a book?

    Hi, i'm readin PHP Objects Pattern and Practice 2nd Edition.
    In the section reserved to the PROTOTYPE PATTERN, i see an UML diagram that do not correspond to the final code.

    It's very simple
    abse.jpg

    And this is the implementation
    PHP Code:
    class Sea {}
    class 
    EarthSea extends Sea {}
    class 
    MarsSea extends Sea {}

    class 
    Plains {}
    class 
    EarthPlains extends Plains {}
    class 
    MarsPlains extends Plains {}

    class 
    Forest {}
    class 
    EarthForest extends Forest {}
    class 
    MarsForest extends Forest {}

    class 
    TerrainFactory {
       private 
    $sea;
       private 
    $forest;
       private 
    $plains;
       function 
    __constructSea $seaPlains $plainsForest $forest ) {
          
    $this->sea $sea;
          
    $this->plains $plains;
          
    $this->forest $forest;
       }
       function 
    getSea( ) {
          return clone 
    $this->sea;
       }
       function 
    getPlains( ) {
          return clone 
    $this->plains;
       }
       function 
    getForest( ) {
          return clone 
    $this->forest;
       }
    }

    $factory = new TerrainFactory( new EarthSea(),
                                    new 
    EarthPlains(),
                                    new 
    EarthForest() );
    print_r$factory->getSea() );
    print_r$factory->getPlains() );
    print_r$factory->getForest() ); 
    As you can see, all methods getSea, getPlains, getForest are fully implemented inside the main class (TerrainFactory), and at runtime they are the only that are used. For what reason in UML diagram the same methods are override in each sublclass (Earth and Mars) ?
    Last edited by American horizo; 04-11-2014 at 01:45 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles