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

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

Difference between TCP and UDP

UDP or User Datagram Protocol is the simplest connectionless transport layer protocol which simply sends packets between applications. It has very less overhead as UDP doesn’t require any session to transfer packets between applications.
Generally Real time protocols (RTP), DNS etc application uses UDP protocol.

TCP or Transmission Control Protocol is a reliable, connection-oriented protocol. TCP maintains a session between application and uses this session to send data across applications. TCP has support of acknowledgements of every packet being transferred and hence it’s reliable protocol but has higher overhead compared to UDP.
Generally FTP, HTTP etc application uses TCP protocol.

(more…)
Difference between TCP and UDP Read More

std::bitset explained with simple example

A Bitset is a standard template library class provided by C++ which can be used to define a fixed length sequence of bits. A value of zero indicates bit is unset whereas 1 indicates bit is set.
This class provides similar functionality as array of Boolean values in more space efficient way. There are lot of useful memory functions also provided by the library which can be used by the programmers to use it directly.

Let’s have a look into std::bitset template class definition.

template <size_t N> class bitset;
Where N = length of bitset (in bits).
(more…)
std::bitset explained with simple example Read More

std::vector explained with simple example

Vector in C++ are part of Standard Library Container Classes which basically has the functionality of dynamic array which are flexible in size.
C++ STL provides a template class definition for Vectors which are very efficient, refined, and easy to use.
It also has lots of very useful member functions which can be used directly in programs for faster implementation.

Let’s have a look into std::vector class template definition.

template <class T, class Allocator = allocator<T>> class vector
where T = data type that is being stored and allocator defines the allocator functions.
(more…)
std::vector explained with simple example Read More

Difference between Copy constructors and Assignment operator

Copy constructor is a special kind of constructor which initializes an object using another object. Compiler always provides a default copy constructor but if needed it can be over-ridden by programmer to meet the requirements.

Assignment operator is basically assigning the new values to already created object. In this case object initialization doesn’t happen as it is already done.

For eg:

class Base{
};

Base b1;
Base b2 = b1; /* Copy constructor as initialization also needs to done */
Base b3;
b3 = b2; /* Assignment operator as object is already created */
(more…)
Difference between Copy constructors and Assignment operator Read More