Differences

This shows you the differences between two versions of the page.

Link to this comparison view

designpatterns [2015/03/25 16:25]
designpatterns [2022/04/16 12:22] (current)
Line 1: Line 1:
 +===== Reference =====
 +
 +  * design pattern matrix 
 +  * http://www.netobjectives.com/download/dpmatrix.pdf
 +  * http://uml.org.cn/sjms/pdf/dpmatrix.pdf
 +  * http://sourcemaking.com/design_patterns# CPlusPlus
 +  * [[Livre]] : http://rzr.online.fr/isbn/2841773507 # Design patterns Tête la première (Broché) fr
 +  * https://github.com/jwasham/coding-interview-university#dont-feel-you-arent-smart-enough# LearN
 +  * https://www.fluentcpp.com/2020/12/18/on-design-patterns-in-cpp/#
 +
 +
 +===== TEMPLATES =====
 +
 +  // file:///~/singleton.hpp
 +  template <class T>
 +  class Singleton
 +  {
 +  public:
 +  static T* get() {
 +    if ( instance == 0 ) instance = new T;
 +    return instance;
 +  }
 +  protected:
 +  Singleton() { }
 +  ~Singleton() {  }
 +  private:
 +  static T* instance;
 +  };
 +
 +  template<class T>
 +  T* Singleton<T>::instance = NULL; // here the tricky part
 +
 +  // file:///~/main.cpp
 +  #include <string>
 +  using namespace std;
 +  #include "singleton.hpp"
 +
 +  int main()
 +  {
 +  Singleton<string>::get();
 +  return EXIT_SUCCESS;
 +  }
 +
 +
 +Note: [[Microsoft]] msvs allows default types , not GCC so avoid those :
 +  template<class T = char> //...
 +
 +
 +===== TEMPLATES & DESIGN PATTERN =====
 +
 +what do u think of this weird code :
 +
 +  /// Design Pattern (with templates)
 +  template <class T>
 +  class VisitorAble {
 +  public:
 +   virtual int visit(T & in_data)=0;
 +  };
 +
 +  template <class T>
 +  class AcceptAble {
 +  public:
 +   virtual int accept(T & in_visitor) { in_visitor.visit( *this ); }
 +  };
 +
 +  class Visitor : public Visitor<Data> { public: ... visit ... };
 +
 +  class Data : public AcceptAble<VisitorAble<Data> >  {};
 +
 +  // recursive template ?
 +
 +
 +===== MORE =====
 +
 +@TaG: [[Design]] [[Pattern]] [[C++]] [[CPlusPlus]] [[templates]] [[DP]] [[pointers]] [[OOP]] [[STL]] [[auto_ptr]] [[boost]]
  
designpatterns.txt · Last modified: 2022/04/16 12:22 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki