Jump to content
Larry Ullman's Book Forums

kleeh

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by kleeh

  1.  

    I'm having trouble understanding/linking the code example to the diagram and definition for the Factory Pattern.
     

    21bsq35.png

    abstract class Shape { ... }
    class Rectangle extends Shape { ... }
    class Triangle extends Shape { ... }
    
    
    abstract class ShapeFactory {
    
    
        static function Create($type, array $sizes) {
    
    
            switch ($type) {
                case 'rectangle':
                    return new Rectangle($sizes[0], $sizes[1]);
                    break;
                case 'triangle':
                    return new Triangle($sizes[0], $sizes[1], $sizes[2]);
                    break;
            }
        }
    }
    
    
    $obj = ShapeFactory::Create($_GET['shape'], $_GET['dimensions']);

    Must be having an off day because I'm not seeing how the abstract factory class is being extended in the code example.

     

    I was unable to find any information in the book explaining the solid arrows or the term concrete, can anyone point me to the right pages, I must be going blind :/

     

    Any help greatly appreciated.

     

     

    edit: ok I think I understand why there was confusion. The UML diagram used in the book is representative of the second reason/example given for using the factory pattern (where a base factory class is extended) but the code example references the first reason given for using a factory class and there is no UML diagram for this. 

     

    I think the problem, at least for me, is that on page 200 where the Rectangle class is shown, there is no "extends". It just says "class Rectangle {".  The Triangle class says "class Triangle extends Shape {".  So I couldn't see how Rectangle was accessing getArea() until I looked at Triangle and realized it was a book mistake. It's also a mistake in the code example for Rectangle.

  2. You could post your information here or send Larry an email directly.  The idea of having an ebook that is released in multiple stages is that the mistakes you find, can be corrected in the next release.

     

    Everyone benefits.

     

    Brent.

    Ok I'll quote what the current version says toward the end the Static Pages section( page 208 in my PDF, page 122 in my nook: "“You can also create a nested directory structure. For example, say you wanted to have a series of static files about the company, stored within the views/site/pages/company directory. To refer to those files, just prepend the value of $_GET['view'] with "company/": /site/page/view/company/board would display the protected/views/site/pages/company/board.php page.”. Since the yii 2 docs say they've eliminated the 'protected' directory, I'm confused why it's referenced here. Just wanted to bring attention to it.
  3. Is there, or shouldn't there be, a place to post potential Errata for the Yii2 book? I've stumbled across a few things here and there and don't see them mentioned in the forum. For instance, on page 684 (as of the PDF versioin I have which I just dowloaded) there are references to the "protected/views/site/pages/company" path. But the Yii2 book and the documentation specify that the "protected" folder has been eliminated.This just leads to confusion in what can be an already-confusing quest for a MVC and Yii noobie.

    Thanks

×
×
  • Create New...