Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Good stuff

KevinL
2006-01-19
2013-04-29
  • KevinL
    KevinL
    2006-01-19

    Hi there,

    Just want to drop a short note and say thank you for sharing your work. 

    Not only did the code samples help me on understanding the different patterns from the C++ perspective, it also showed me some useful coding styles and techniques here and there (namespace usage, putting access modifiers right before the methods, auto_ptr usage etc).

    Thanks.

     
    • Joe
      Joe
      2006-01-20

      The code has been useful to me as well, thanks.  Couple of questions you ...

      1. I'm using the Solaris CC compiler with your code and it doesn't like the syntax you use for your pure virtual destructor that seem to have an empty body - e.g.:
          public: virtual ~PizzaStore() = 0 {
          }
      I've had to change this to:
          public: virtual ~PizzaStore() {}

      I've never seen your syntax used before, it this a MS specify C++ syntax? and what does it accomplish?  I'ld assuming your trying to define an empty destructor at the same time your making is pure virtual [sortof telling it subclasses must redefine it, but here it is..?].  If would be helpful if you provide an explaination.

      2.  If you could, when you get some of the Gold version patterns implementation completed, please make them available as you get them done.  I've started a study group and have been using the Silver versions [with modifications so I could compile], having versions that make more use of the stl would be educational.

      Thanks...

       
    • Joe
      Joe
      2006-01-20

      Also, I'm not exactly sure what the Solaris CC complier doesn't like, for the Abstract Factory get the warnings below when I compile....{I need to investigate this abit more]...

      kansparc004 (Pizzaaf) 89 % CC -o pizzaaf Pizzaaf.cpp
      "Pizza.hpp", line 42: Warning: name hides HeadFirstDesignPatterns::Factory::Abstract::Pizza::name.
      "CheesePizza.hpp", line 16: Warning: ingredientFactory hides HeadFirstDesignPatterns::Factory::Abstract::CheesePizza::ingredientFactory.
      "VeggiePizza.hpp", line 16: Warning: ingredientFactory hides HeadFirstDesignPatterns::Factory::Abstract::VeggiePizza::ingredientFactory.
      "PepperoniPizza.hpp", line 16: Warning: ingredientFactory hides HeadFirstDesignPatterns::Factory::Abstract::PepperoniPizza::ingredientFactory.
      "ClamPizza.hpp", line 16: Warning: ingredientFactory hides HeadFirstDesignPatterns::Factory::Abstract::ClamPizza::ingredientFactory.
      5 Warning(s) detected.
      ...
      For all ingredientsFactory warnings, these line numbers are all at the line with:
      "public: void prepare() const {"

       
    • gpuchtel
      gpuchtel
      2006-01-20

      Classes that are intended to be used as a base class (one from which you would derive other classes ‘should’ have a ‘virtual’ destructor; as Scott Meyers points out in Item #7 of “Effective C++ (Third Edition)” pp 40-41 “because C++ specifies that when a derived class object is deleted through a pointer to a base class with a non-virtual desctructor, results are undefined.”

      Declaring virtual destructors does not imply that a subclass should override it, fact is, destructors cannot be overriden.

      I declared it pure to ensure the base class as at least a single virtual method, thereby, declaring it and abstract base class; however, it must have a ‘definition’ or the compiler will complain. In my case I defined an empty body in-place in the header file (to keep the example more Java like), which might be one of two things 1) the MS compiler tolorates it, or 2) it is ANSI C++ and Solaris CC does yet support it. In either case, the destructor should be ‘pure’. Removing the pure declaration (= 0) should not alter the logic of the example, but it would not be a ‘good’ C++   practice to do so, rather, eliminate the empty body and define the destructor in the .cpp module.

      In a .hpp file…

          public: virtual ~PizzaStore() = 0;

      In a .cpp file…

          PizzaStore::~PizzaStore() {}

      The thought of posting individual pattern examples when they are completed has crossed my mind. I am currently working on creating examples for the ‘leftover’ patterns. I consider them a ‘Silver’ version, but I can make them available as I complete them. I am about 80% complete with the ‘Bridge’ and ‘Builder’ patterns.

      Hope this helps,
      Glenn

       
    • Joe
      Joe
      2006-01-20

      Thanks for the info, now I understand.  I've got Meyer's 2nd edition and item #14 "Item 14:  Make sure base classes have virtual destructors" discusses this - just read it.

      Examples of the leftover patterns will be great, it would be useful to make them available as you get them done.

      Thanks again