After we discuss the concept of immutability, now let's develop the immutable object. We will start with the mutable object first, then refactor it into an immutable one.
Now, let's go further. We will create another class to design an immutable object. First, we will create a mutable class named MutableEmployee
. We have some fields and methods in that class. The header of the class will be like the following piece of code:
/* mutableemployee.h */ #ifndef __MUTABLEEMPLOYEE_H__ #define __MUTABLEEMPLOYEE_H__ #include <string> class MutableEmployee { private: int m_id; std::string m_firstName; std::string m_lastName; double m_salary; public: MutableEmployee( int id, const std::string& firstName, const std::string& lastName, const double& salary); MutableEmployee(); void SetId(const int id...