

So, in this case, you would actually want to create a SetClassroomSize() method.

And throwing exceptions inside of a mutator (or accessor) is a bad form. In truth, you would most likely want to throw an exception when the classroom size exceded a reasonable value, rather than override that value. Using the mutator, you don't have to burden the user of your class with calling a SetClassroomSize(300), and instead allow them to assign your property like a field. You can get and set its value easily: int localVariable = 3000000 īut what if you know the entire school only has 300 chairs? You use a mutator to limit the assignment value to <= 300. So, you have a public field, classroomSize. Mutators (setters) and Accessors (getters) are a sneaky way of overriding the assignment operator. Now the setter for the above class can be written like this: Public Class Account

Hence inorder to provide consistency in the data of an object (while either reading/setting) we have getters and setters resp. Dim acc as New Account("CustID-1234")Īcc.Balance = "Ten thousand" 'this is wrong Lets say it has a property called Balance which is of string datatype (for example sake), but has only numeric values. in the setter implementation of a class called Account. It is a way of reading/setting values of the private members/variables after a layer where some logic can be implemented. To make a long story short it is just the way a client uses/interacts with the object in order to force him/her to follow a particular pattern of usage.
