Cisco CloudCenter: Get the Hybrid IT Advantage


Definition - What does Mutator mean?

A mutator, in the context of C#, is a method, with a public level of accessibility, used to modify and control the value of a private member variable of a class. The mutator is used to assign a new value to the private field of a type. It forms a tool to implement encapsulation by only controlling access to the internal field values that must be modified.

The benefits of using a mutator include:

  • Prevents the user from directly accessing the private data of an object instance and allows access only through public methods to prevent data corruption.
  • Provides flexibility in modifying the internal representation of the fields of an object that represents the internal state without breaking the interface used by the object's clients.
  • Ability to include additional processing logic like validation of a values set, triggering of events, etc., during the modification of the field in the mutator.
  • Provides the synchronization that is necessary for multithreading scenarios.
  • Includes a provision to override the mutator declared in a base class with the code in the derived class.

Techopedia explains Mutator

A mutator is usually provided with an accessor that returns the value of the member variable. For data members that are immutable, the mutator should not be provided.

For example, StudentData can be a class that stores a student's details, such as name, address, grade, etc. There can be a public method, SetGrade in the class. StudentData is the mutator to update the StudentData object from the code that uses the object.

While a mutator is implemented in C++ by an explicit public method to modify a private field, C# introduces "properties" as a new feature that implements a mutator to modify field values as well as an accessor to fetch the field. Each property is represented in the common intermediate language code with a pair of methods prefixed with "get_"(accessor) and "set_"(mutator) under the hood. They are called internally by the common language runtime (CLR). This simplifies the code and sometimes allows for the performance of mathematical operations.

The mutator is not often used in objects, where the object's behavior is considered rather than how it performs.

This definition was written in the context of C#
Share this:

Connect with us

Email Newsletter

Join thousands of others with our weekly newsletter

The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.