Difference between an inspector and a mutator - C++

What is the difference between an inspector and a mutator?

- The get() functions are usually refered to as inspectors as that just retrieve the data values from the source. However, mutators that can be refered to as set() finctions change the values of the data source.

What is the difference between an inspector and a mutator?

- An object’s state is returned without modifying the object’s abstract state by using a function called inspector. Invoking an inspector does not cause any noticeable change in the object’s behavior of any of the functions of that object.
- A mutator, on the other hand, changes the state of an object which is noticeable by outsiders. It means, it changes the abstract state of the object.
- The following code snippet depicts the usage of these two functions :
class ShoppingCart
{
   public:
       int addItem();    //Mutator
       int numItems() const;    //Inspector
};
- The function addItems() is a mutator. The reason is that it changes the ‘ShoppingCart’ by adding an item.
- The function numItems() is an inspector. The reason is that it just updates the count of number of items in the ‘ShoppingCart’.
- The const declaration followed by int numItems() specifies that numItems() never change the ‘ShoppingCart’ object..
What is pointer? - C++
What is pointer? - A pointer is a variable that holds a memory address....
Pointer to constant vs. pointer constant - C++
Pointer to constant vs. pointer constant - Pointer to constant points to a value that does not change and is declared....
What are function pointers?
What are function pointers? - A function has a physical location in the memory which is the entry point of the function...
Post your comment