Singleton vs Static class

The singleton design pattern ensures that at any point of time a class has one and only one instance which can be accessed globally. This design pattern is useful in cases where exactly one instance is needed to co-ordinate between different modules of a software. Singleton design pattern can be used as a logger class or memory/thread pool classes for which only one instance of object is needed.

(more…)
Singleton vs Static class Read More

Proxy vs Observer design pattern

The Proxy design pattern allows to define a “proxy” class which will act as a wrapper object which will be called by the client to access the product object without exposing the details. This proxy class can also be used to add extra functionality without changing the product behavior. This design pattern can be used in cases to provide additional security access to an existing product or providing an interface for remote resources. General class diagram of proxy pattern is shown below.

(more…)
Proxy vs Observer design pattern Read More

C++11: Override and Final keyword

The explicit override and final keywords in C++11 (Introduction to C++11) enhances the polymorphism capabilities of C++. These new features provide extra control over virtual functions to the programmer. In this post, we will discuss about these new features and their usage.

Override

The explicit override keyword overrides the marked virtual function in derived class as override version of base class virtual functions. This ensures that the overrides are done by the programmer intentionally which reduces the chances of unwanted mistakes by providing clarity and hence improves the code readability and maintainability.

(more…)
C++11: Override and Final keyword Read More

C++11: Uniform Initialization explained with Simple example

In C++11 (Introduction to C++11), “Uniform initialization” syntax is introduced to initialize variables which provides a consistent syntax for all types of data variables initialization. This syntax is defined for all types of objects, arrays etc. In this post we are focusing on Uniform initialization syntax with some coding examples.

Earlier there were multiple ways to initialize variables. For example: basic data type variables could be initialized using assignment operator whereas class objects could be initialized using a constructor.

In C++11, a uniform way of initializing variables is introduced which is called “Uniform Initialization” syntax.

Let’s have a look at the sample code example to understand the usage of uniform initialization.

(more…)
C++11: Uniform Initialization explained with Simple example Read More

C++11: Initializer Lists Explained with Simple Example

In C++11 (Introduction to C++11), Initializer lists are a major addition to the C++ language. In this post we are focusing on Initializer lists with some coding examples.

To understand Initializer lists, we need to first understand the constructors. Constructors are special member functions of a class which is used to initialize the object in desired way. Constructors has the same name as that of class. There could be multiple constructors defined in a class which could be selected based on invoking conditions.

(more…)
C++11: Initializer Lists Explained with Simple Example Read More

Python string operations: Indexing and Slicing

In Python, a string is basically an ordered sequence of characters to store text-based information. String data type in python supports lot of methods to process/manipulate the data.

In this article today, we will discuss about some of the basic operations which are supported by python string data type which are very useful to use and comes in handy while programming.

Before moving please have a look into Python String basics.

(more…)
Python string operations: Indexing and Slicing Read More