New Google Chrome look

Disponibil deja in versiunea de Google Chrome “Canary” noua interfata a browserului pare sa fie una mai compacta si mai aratoasa fata de vechea versiune, cel putin din punctul meu de vedere. Pentru a o activa trebuie sa descarcati si sa instalati varianta “beta/alpha” a browserului de aici https://www.google.com/chrome/browser/canary.html. Mai apoi navigati la adresa: chrome://flags/#top-chrome-md si de acolo selectati optiunea Refresh.  

Singleton done right in C++ 11

Today searching the internet I’ve found a “cool” and simple method to create a safe singleton that performs well in multithreading environment. With a small amount of lines you can achieve both: safe initialization and multithreading safety. class Singleton { static std::once_flag onceFlag; static Singleton* instance; public: static Singleton& getInstance(){ std::call_once(onceFlag, []{ instance = new Singleton(); }); return *instance; } private: Singleton(){}; }   As c++ documentation says the: The class std::once_flag is a helper structure for std::call_once. An object ...

Mai mult

The PIMPL idiom

The purpose Remove compilation dependencies on internal class implementations and improve compile times. The story behind When a header file changes, any files that #include that file will need to be recompiled. In the case of a class header, this is true even if those changes only apply to private members of the class. The PIMPL idiom hides private members from any users of the header file, allowing these internal details to change without requiring recompilation of the client code. ...

Mai mult

Inheritance in C++

The question: I looked and couldn’t find a good explanation of the difference between public, private, and protected inheritance in C++. All of the questions I’ve found deal with specific cases. What is the difference in general? The answer: There are three accessors that I’m aware of: public, protected and private. Lets take the following example: class Base { public: int publicMember; protected: int protectedMember; private: int privateMember; }; Everything that is aware of Base is also aware that Base ...

Mai mult

Testarea unui singleton folosind Mock Object

Problema De multe ori testarea singleton-urilor este una foarte anevoioasa. Folosirea acestui pattern pe langa ca aduce multa simplitate in ceea ce priveste accesul la variabilele protejate de singleton ingreuneaza testarea codului. Urmatorul cod prezinta solutia clasica, si nu neaparat cea mai buna, de implementare a unui singleton: class Singleton { public: static Singleton* getInstance() { if (!instance) { instance = new Singleton; } return instance; } private: Singleton(){} static Singleton* instance; }; Pentru a utiliza acest singleton in cadrul ...

Mai mult

Factory Method Design Pattern

Dupa singleton, un alt pattern destul de des folosit in crearea obiectelor este cel denumit “factory method”. Pe scurt acesta izoleaza partea de creare si parametrizare a unui obiect intr-o metoda statica ce are rolul, initial, de a crea obiectul iar mai apoi de a-l parametriza facandu-l gata pentru a fi utilizat.

Singleton Pattern

Singleton sau “instanta unica” este un design pattern creational. Acesta constrange numarul obiectelor pe care o clasa le defineste. Singleton-ul este frecvent intalnit la definirea accesului la resurse “unice” in sistem precum: baze de date resurse hardware (registri, componente harware: modem, gps, gprs …)