Enumerations in C++

An enumeration is a user-defined type that consists of a set of named integral constants that are known as enumerators.

There are scoped enum and non-scoped enum.

Scoped Enum: enum class Suit {Diamonds, Hearts, Clubs, Spades };

Non-Scoped Enum: enum Suit {Diamonds, Hearts, Clubs, Spades };

Every name in an enumeration is assigned an integral value. By default, the first value is assigned 0, the next one is assigned 1, but you can explicitly set the value of an enumerator.

The benefits of using enumerations include:

  1. Makes code easier to read, which means it is less likely that errors will creep into it.
  2. Make it easy to change values in the future.
Advertisements

Factory Method in C++

A factory method is a static method of a class that returns an object of the class’s type. But unlike a constructor, the actual object it returns might be an instance of a subclass. Another advantage of a factory method is that it can return existing instances multiple times.

Also, the factory method can be defined in the base class, or, in a separate factory class.

What is RPC?

Remote Procedure Call (RPC) is an interprocess communication technique that allows client and server software to communicate.

Computer operating systems and programs have steadily gotten more complex over the years. The growing intricacy of systems makes it more difficult for developers to avoid errors during the development process.

RPC is designed to mitigate these issues by providing a common interface between applications. RPC serves as a go-between for client/server communications. RPC is designed to make client/server interaction easier and safer by factoring out comon tasks, such as security, synchronization, and data flow handing., into a common library so that developers do not have to dedicate the time and effort into developing their own solutions.

Singleton Pattern in C++

Most contents are selected from http://www.codeproject.com/Articles/1921/Singleton-Pattern-its-implementation-with-C

Suppose we have to use a single object of class throughout the lifetime of an application. in C++, we can declare a global object. Or use a more practical solution, which is to get a single object by declaring a class, which contains only static methods, and this is singleton design pattern. But remember that a class with only static methods and variables are not a good object oriented design.

The Singletons are often used to control access to resources such as database connections or sockets. ♠

By using a private constructor and a static method to create and return an instance of the class is a popular way for implementing Singleton Pattern.