Results 1 to 4 of 4

Thread: What are matching mutator methods?

  1. #1
    Join Date
    Oct 2009
    Posts
    2

    What are matching mutator methods?

    Hi am pretty new to Object oriented programming. I want to know what are matching mutator methods and how does one use them and where? what is the use of a mutator method? Explanation through an example will be preferred.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    re: What are matching mutator methods?

    Mutator method is a method used to control the changes made to a variable. they are usually used in Object Oriented Programming(OOP) for encapsulation purposes. There are two mutators as such, One called "setter" which sets some value to a variable and other is "getter" which gets the value of a variable. The mutators can be used in programming languages other than the Object oriented ones. the difference being that in OOP languages, they are exclusively used for encapsulation purposes, where we want the variable hidden from changes in the outside code. An example of a code using the setters and getters in a java program is given below;
    Code:
    public class Test {
        private String name;
     
        /**
        *@return the name
        */
        public String getName() {
            return name;
        }
     
        /**
        * newName is the name to set
        */
        public void setName(String newName) {
            name = newName;
        }
    }
    Hope you got what you asked for. In case of further querries, please so reply.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    re: What are matching mutator methods?

    A mutator is basically a method that changes a variable inside a class, variables that are either private or protected. This is what a mutator is technically speaking, but what you are referring to, that is a matching mutator method is what we call "setters" which set values to a private or protected variable like in the code below, where we are setting the name of a "newStudentName" to the "studentName";
    Code:
    public void setNewStudent(String newStudentName)
    {
    this.studentName = newStudentName;
    }
    In case you did not get it, let me know about it.

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    re: What are matching mutator methods?

    Well i thought this further information would be helpful for people who are learning C# and not Java. In C# there are properties which are special type of class members, there are no explicit methods unlike Java. a code that gives the get and set method is given below;
    Code:
    public class Test 
    {
        private int num;
     
         /// gets or sets a student's name
        public int Number 
        {
            get 
            {
                return num;
            }
     
    	set 
            {
                num = 5;
            }
        }
        /// i have set the num to value 5, which can be any number
    }

Similar Threads

  1. String matching algorithm
    By Kaustubh m in forum Software Development
    Replies: 4
    Last Post: 21-07-2010, 10:10 AM
  2. Problem in matching Regex
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 04:12 AM
  3. Problem in pattern matching
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 04-02-2010, 12:32 AM
  4. Partial matching of cell in Microsoft Excel
    By KANAN14 in forum Windows Software
    Replies: 3
    Last Post: 04-12-2009, 02:20 AM
  5. JAVA Help - Background change by color matching
    By Daren in forum Software Development
    Replies: 4
    Last Post: 12-05-2009, 08:41 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,631,936.61905 seconds with 16 queries